akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int H,N;
string s[11][2];
string t[3][2][2];
bool S[20][2][2];
bool T[3][2][2][2];
int dx[9]={1,1,1,0,0,0,-1,-1,-1},dy[9]={1,0,-1,1,0,-1,1,0,-1};
bool check(int id,int x)
{
	for(int i=0;i<2;i++)for(int j=0;j<2;j++)for(int k=0;k<2;k++)
	{
		if(T[id][i][j][k]&&S[x+i][j][k])return false;
	}
	return true;
}
int f()
{
	int ret=0;
	for(int i=0;i<N;i++)
	{
		int id=18;
		while(check(i,id))id--;
		id++;
		for(int K=0;K<2;K++)for(int I=0;I<2;I++)for(int J=0;J<2;J++)
			S[id+K][I][J]|=T[i][K][I][J];
		for(int K=19;K>0;K--)
		{
			if(S[K][0][0]&&S[K][0][1]&&S[K][1][0]&&S[K][1][1])
			{
				ret++;
				for(int I=K;I<19;I++)
				{
					S[I][0][0]=S[I+1][0][0];
					S[I][0][1]=S[I+1][0][1];
					S[I][1][0]=S[I+1][1][0];
					S[I][1][1]=S[I+1][1][1];
				}
				S[19][0][0]=S[19][0][1]=S[19][1][0]=S[19][1][1]=0;
			}
		}
	}
	return ret;
}
main()
{
	s[0][0]=s[0][1]="##";
	while(cin>>H>>N,N)
	{
		for(int i=0;i++<H;)
		{
			cin>>s[i][0]>>s[i][1];
		}
		for(int i=0;i<N;i++)
		{
			cin>>t[i][0][0]>>t[i][0][1]>>t[i][1][0]>>t[i][1][1];
		}
		int ans=0;
		for(int i=0;i<(N>=1?9:1);i++)
		{
			bool flag1=true;
			if(N>=1)
			{
				for(int K=0;K<2;K++)for(int I=0;I<2;I++)for(int J=0;J<2;J++)
					T[0][K][I][J]=0;
				for(int K=0;K<2;K++)for(int I=0;I<2;I++)for(int J=0;J<2;J++)
				{
					int tx=I+dx[i],ty=J+dy[i];
					if(t[0][K][I][J]=='.'||0<=tx&&tx<2&&0<=ty&&ty<2)
					{
						if(t[0][K][I][J]=='#')T[0][K][tx][ty]=true;
					}
					else
					{
						flag1=false;
						break;
					}
				}
			}
			if(!flag1)continue;
			for(int j=0;j<(N>=2?9:1);j++)
			{
				bool flag2=true;
				if(N>=2)
				{
					for(int K=0;K<2;K++)for(int I=0;I<2;I++)for(int J=0;J<2;J++)
						T[1][K][I][J]=0;
					for(int K=0;K<2;K++)for(int I=0;I<2;I++)for(int J=0;J<2;J++)
					{
						int tx=I+dx[j],ty=J+dy[j];
						if(t[1][K][I][J]=='.'||0<=tx&&tx<2&&0<=ty&&ty<2)
						{
							if(t[1][K][I][J]=='#')T[1][K][tx][ty]=true;
						}
						else
						{
							flag2=false;
							break;
						}
					}
				}
				if(!flag2)continue;
				for(int k=0;k<(N>=3?9:1);k++)
				{
					bool flag3=true;
					if(N>=3)
					{
						for(int K=0;K<2;K++)for(int I=0;I<2;I++)for(int J=0;J<2;J++)
							T[2][K][I][J]=0;
						for(int K=0;K<2;K++)for(int I=0;I<2;I++)for(int J=0;J<2;J++)
						{
							int tx=I+dx[k],ty=J+dy[k];
							if(t[2][K][I][J]=='.'||0<=tx&&tx<2&&0<=ty&&ty<2)
							{
								if(t[2][K][I][J]=='#')T[2][K][tx][ty]=true;
							}
							else
							{
								flag3=false;
								break;
							}
						}
					}
					if(!flag3)continue;
					for(int i=0;i<20;i++)for(int j=0;j<2;j++)for(int k=0;k<2;k++)
						S[i][j][k]=0;
					for(int i=0;i<=H;i++)
					{
						for(int j=0;j<2;j++)for(int k=0;k<2;k++)
							S[i][j][k]=s[i][j][k]=='#';
					}
					ans=max(ans,f());
				}
			}
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3156
#include<iostream>
#include<algorithm>
#include<vector>
#include<iterator>
#include<cmath>
#include<iomanip>
using namespace std;

int main()
{
    double a, b, h, m, theta, ans;
    cin>>a>>b>>h>>m;
    h = ((h/6.0)+(m/360.0))*2.0*acos(0.0);
    m = (m/30.0)*2.0*acos(0.0);
    theta = (h>m)? h-m:m-h;
    ans = pow(a*a+b*b-2*a*b*cos(theta), 0.5);
    cout<<fixed<<setprecision(12)<<ans<<endl;
}


Measured memory_bytes: 4356
fun main(args: Array<String>) {
    val x = readLine()!!.toInt()
    val bekiList = mutableSetOf<Int>()
    bekiList.add(1)
    for (i in 2..34) {
        var p = 2
        while (Math.pow(i.toDouble(), p.toDouble()) <= 1000) {
            bekiList.add(Math.pow(i.toDouble(), p.toDouble()).toInt())
            p++
        }
    }
    println(bekiList.filter { it <= x }.max())
}



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

using namespace std;

typedef long long ll;

int main(){
	char c;
	cin >> c;
	if(c == 'A'){
		cout << 'T';
	}else if(c == 'G'){
		cout << 'C';
	}else if(c == 'C'){
		cout << 'G';
	}else if(c == 'T'){
		cout << 'A';
	}	
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    if n % 2 == 1 {
        println!("0");
        return;
    }

    let mut sum = 0;
    let mut now = 10;
    while n >= now {
        sum += n/now;
        now *= 5;
    }
    println!("{}", sum);
}


Measured memory_bytes: 8572
use proconio::input;
use std::cmp;

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    //dp[i] = (m1, m2) 長さiの整数列 m1: 組の個数 m2: 末尾からの条件を満たす個数
    let mut dp = vec![(1, 0); n];

    // check_v[i] = (m1, m2) m1: 1が既に登場しているか表す m2: 直近で1が登場した位置
    let mut check_v = vec![(false, 0); 21];
    for i in 0..=20 {
        if (a[0] >> i) & 1 != 0 {
            check_v[i] = (true, 0);
        }
    }

    dp[0] = (1, 1);
    for i in 1..n {
        let mut flag = false;
        let mut pos = 0;
        for j in 0..=20 {
            if (a[i] >> j) & 1 != 0 {
                if check_v[j].0 {
                    flag = true;
                    pos = cmp::max(pos, check_v[j].1);
                }
                check_v[j] = (true, i);
            }
        }
        if flag {
            for j in 0..=20 {
                if check_v[j].1 < pos {
                    check_v[j] = (false, 0);
                }
            }
            dp[i] = (dp[i-1].0 + (i - pos), i - pos);
        } else {
            dp[i] = (dp[i].0 + dp[i - 1].0 + dp[i - 1].1, dp[i - 1].1 + 1);
        }
    }

    /*
    for i in 0..n {
        println!("dp[{}]: {:?}", i, dp[i]);
    }
    */
    println!("{}", dp[n-1].0);
}

Measured memory_bytes: 7932
import itertools
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
cnt = 0
cnt1 = 0
cnt2 = 0
a = []
for i in range(1, n+1):
    a.append(i)

for j in itertools.permutations(a):
    cnt += 1
    jk = list(j)
    if jk == p:
        cnt1 = cnt
    if jk == q:
        cnt2 = cnt
print(abs(cnt1 - cnt2))

Measured memory_bytes: 3064
#include <stdio.h>

int main() {
	int i, j, jj, N, a[100], max = 0;
	int Alice = 0, Bob = 0;

	scanf("%d", &N);

	for (i = 0; i < N; i++) scanf("%d", &a[i]);

	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			if (a[j] >= max) {
				max = a[j];
				jj = j;
			}
		}
			if (i % 2 == 0) Alice += max;
			else Bob += max;
			a[jj] = 0;
			max = 0;
	}

	printf("%d\n", Alice - Bob);

	return 0;
}

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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

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

int main() {
  int n;
  cin>>n;
  VI v(n);
  REP(i,n){
    cin >> v[i];
  }

  SORT(v);

  ANS(v[n / 2] - v[n / 2 - 1]);
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int gcd(int x, int y){
    if(y == 0) return x;
    return gcd(y,x%y);
}


int main(){
    int N,X; cin >> N >> X;
    vector<int> x(N);
    rep(i,N) cin >> x[i];
    int ans = abs(X-x[0]);
    repr(i,1,N){
        ans = gcd(ans,abs(X-x[i]));
    }
    cout << ans << endl;
}



Measured memory_bytes: 640
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int n=stdIn.nextInt(),a[]=new int[100],i,j,t;
		for(i=0;i<n;i++)a[i]=stdIn.nextInt();
		for(i=0;i<n;i++){
			t=a[i];
			j=i-1;
			while(j>=0&&a[j]>t){
				a[j+1]=a[j];
				j--;
			}
			a[j+1]=t;
			for(j=0;j<n-1;j++)System.out.print(a[j]+" ");
			System.out.println(a[n-1]);
		}
	}
}


Measured memory_bytes: 31524
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
    string s,c,first,last;
    int q,i,a,b;
    bool flag = true;
    cin>>s>>q;
    for(i=0;i<q;i++){
        cin>>a;
        if(a == 1){
            flag = !flag;
        }
        else{
            cin>>b>>c;
            if(flag == true && b==1){
                first = c + first;
            }
            if(flag == false && b==2){
                first = c + first;
            }
            if(flag == true && b==2){
                last = last + c;
            }
            if(flag == false && b==1){
                last = last + c;
            }
        }
    }
    s = first + s + last;
    if(flag ==false) reverse(s.begin(),s.end());
    cout<<s<<endl;
}

Measured memory_bytes: 1464
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let mut n = read::<i64>();
  let mut l = read::<i64>();

  let mut vec_l = vec![];
  let mut target = 1000000000;

  for i in 1..n + 1 {
    vec_l.push(i + l - 1);
    if (i + l - 1).abs() < target {
      target = (i + l - 1).abs()
    }
  }

  let sum = vec_l.iter().sum::<i64>();
  if sum < 0 {
    println!("{:?}", sum + target);
  } else {
    println!("{:?}", sum - target);
  }

}


Measured memory_bytes: 4352
if __name__ == '__main__':

	#入力
	N = int(input())
	score_lst = [int(a) for a in input().split()]
	grade_lst = []
	for i in score_lst:
		grade = int(i / 400)
		if grade > 7:
			grade = 8
		grade_lst.append(grade)

	count = 0

	for i in range(0,8):
		if grade_lst.count(i) > 0:
			count += 1

	if count != 0:
		min_count = count
	else:
		min_count = 1
	max_count = count + grade_lst.count(8)

	print("{} {}".format(min_count,max_count))

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

vector<ll> to[200005];

int main(){
	ll n;
	cin >> n;
	REP(i,n-1){
		ll a;
		cin >> a;
		to[a].push_back(i+1);
	}
	REP(i,n){
		cout << to[i].size() << endl;
	}
    return 0;
}



Measured memory_bytes: 14524
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

typedef long long ll;

string T[] = {"dream", "erase", "eraser", "dreamer"};

const int Maxn = 100010;
bool dp[Maxn];

int main() {
    string s;
    cin >> s;
    int n = (int) s.size();

    reverse(s.begin(), s.end());
    for (string &t : T){
        reverse(t.begin(), t.end());
    }

    int i = 0;
    while (i < n) {
        string tmp;

        if (i + 5 <= n) {
            tmp = s.substr(i, 5);
            if (tmp == T[0] || tmp == T[1]) {
                i += 5;
                continue;
            }
        }

        if (i + 6 <= n) {
            tmp = s.substr(i, 6);
            if (tmp == T[2]) {
                i += 6;
                continue;
            }
        }

        if (i + 7 <= n) {
            tmp = s.substr(i, 7);
            if (tmp == T[3]) {
                i += 7;
                continue;
            }
        }

        cout << "NO" << endl;
        return 0;
    }

    cout << "YES" << endl;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> As(N);
    for (auto & a : As) cin >> a;
    cout << *max_element(As.begin(), As.end()) - *min_element(As.begin(), As.end()) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define M1 1000000007
#define M2 998244353

#define ste(v) v.begin(),v.end() 
#define lb lower_bound
#define vb v.begin()

#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define bfl(i,a,b) for(ll i=b-1;i>=a;i--)
#define f(i,n)     for(int i=0;i<n;i++)
#define bf(i,n)    for(int i=n-1;i>=0;i--)


#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define bn "\n"

//------------------------------------------------------------------------ 
// #define V(a) vector<a>
// #define vt() vector< tuple < int ,int ,int > > ;
// #define vector< int ,int > pv;
// vector< pair <int,int> > vect;


//------------------------------------------------------------------------

ll modI(ll a,ll m);
ll gcd(ll a,ll b);
ll powM(ll x,ll y,ll m);
ll swap(ll a,ll b);

void swap(ll& a,ll& b)
{
    ll tp=a;
    a=b;
    b=tp;
}

ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}

ll powM(ll x,ll y,ll m)
{
    ll answer=1,r=1;
    x%=m;
    while(r>0&&r<=y)
    {
        if(r&y)
        {
            answer*=x;
            answer%=m;
        }
        r<<=1;
        x*=x;
        x%=m;
    }
    return answer;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

//---------------------------------------------------------------------------

// variable = Expression1 ? Expression2 : Expression3
// max = (n1 > n2) ? n1 : n2; 
// (n>m) ? cout<<"True"<<endl:cout<<"false"<<endl ;

// ---------------------------------------------------------------------------	

// int n;cin>>n;int a[n];for(int i=0;i<n;i++)cin>>a[i];    
// for(int i=0;i<n;i++)cout<<a[i];
// int a,b;cin>>a>>b;   

//----------------------------------------------------------------------------

// vector< tuple < int ,int ,int > > tv;
// vector< int ,int > pv;


//----------------------------------------------------------------------------


int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	int tt=1;
   // cin>>tt;
	while(tt--)
	{
	       int n; cin>>n;
	vector <int> v(n);
	f(i,n) cin>>v[i];
	sort(ste(v));
	int answer = 0;

    bf(i,n)
	{
	    int g = v[i];
	    if(i<n-1 && v[i+1]==g) 
	     continue;
	    if(i==0)
	      { answer++; continue; }
	    bool flag=1;
	  
	    fl(j,1,sqrt(g)+1)
	    {
	        if(g%j==0)
	        {
	            auto ptr = lb(vb,vb+i,j);
	            if(ptr!=vb+i && *ptr==j)
	               { flag=0; break; }
	            ptr = lb(vb,vb+i,g/j);
	            if(ptr!=vb+i && *ptr==g/j)
	               { flag=0; break; }
	        }
	    }
	    if(flag) answer++;
	}
  p1(answer);
	   
	   
	   
	    
	}
	
	return 0;
}


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

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

    for ( int i = n - 1; i > 0; i--){
        cout << a[i] << ' ';
    }
    cout << a[0] << endl;
    return 0;
}


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

int main(){
    string str;
    int q;
    cin >> str >> q;
    rep(i, q){
        string ord;
        cin >> ord;
        int a, b;
        if(ord=="print"){
            cin >> a >> b;
            cout << str.substr(a, b-a+1) << endl;
        }else if(ord=="reverse"){
            cin >> a >> b;
            string s = str.substr(a, b-a+1);
            string revs;
            rep(j, b-a+1){
                revs += s[s.size()-j-1];
            }
            str = str.replace(a, b-a+1, revs);
        }else if(ord=="replace"){
            string reps;
            cin >> a >> b >> reps;
            str = str.replace(a, b-a+1, reps);
        }
    }
    
    return 0;
}


Measured memory_bytes: 3240
#include<stdio.h>
int main() {
	int n, q, i, j,sv=0, ct = 0, at = 0;
	int S[10000];
	int T[10000];
	int save[10000];

	scanf("%d", &n);
	for (i = 0; i<n; i++) {
		scanf("%d", &S[i]);
	}
	scanf("%d", &q);
	for (i = 0; i<q; i++) {
		scanf("%d", &T[i]);
	}


	for (i = 0; i<n; i++) {
		for (j = 0; j<q; j++) {
			if (S[i] == T[j]) {
				save[sv] = T[j];
				ct++;
				sv++;
				break;
			}
		}
	}
	at = ct;

	for (i = 0; i<ct; i++) {
		if (save[i] < 0)continue;
		for (j = i + 1; j < ct; j++) {
			if (save[i] == save[j]) {
				save[j] = -1;
				at--;
			}
		}
	}
	/*for (i = 0; i < ct; i++) { printf("%d\n", save[i]); }*/

	printf("%d\n", at);
	return 0;
}




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

int main(){
  int A,B,x,y,z;
  cin >> A >> B;
  x = A + B;
  y = A - B;
  z = A * B;
  if(x > y && x > z)
    cout << x;
  else if(y > z)
    cout << y;
  else
    cout << z;
  return 0;
}

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

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

int a, b, c;

int main()
{
    int i, j;

    scanf("%d%d", &a, &b);
    printf("%d", max({a+b, a-b, a*b}));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
  
int main() {
  long long  a, b, c;
  cin >> a >> b;
  c = 1;
  rep(i,min(a,b) - 1){
    if(a % (min(a,b) - i) == 0 && b % (min(a,b) - i) == 0){
      c = min(a,b) - i;
      break;
    }
  }
  cout << a * b / c;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  string a;
  cin >> a;
  int ans = 0;
  for(int i=a.size()-1;i >= 0;i--){
    if(i%2){
      continue;
    }
    string b = a.erase(i);
    if(b.substr(i/2) == b.substr(0,i/2)){
      ans = i;
      break;
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

int main() {
    ll N;
    cin >> N;
    string s;
    cin >> s;
    if (N % 2 == 1) {
        cout << "No" << endl;
    } else {
        rep(i, 0, N/2) {
            if (s[i] != s[N/2+i]) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
}



Measured memory_bytes: 888
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int n;
vector<int> a(100005), memo(100005);

int frog( int i ){
    if ( i == n - 1 )
        return 0;
    
    if ( memo[i] != - 1)
        return memo[i];
        
    long long j = 1e9, jj = 1e9;
    if( i + 1 < n)
        j = abs( a[i] - a[i + 1]  ) + frog( i + 1 );
    if ( i + 2 < n )
        jj = abs( a[i] - a[i + 2] ) + frog( i + 2 );
    
    return memo[i] = min(j, jj);
}

int main()
{
    cin >> n;
    for ( int i = 0; i < n; i++ )
        cin >> a[i];
    fill_n( memo.begin(), n, -1 );
    cout << frog(0) << endl;
    return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <cstring>
using namespace std;
char S[100005];
int N;
void Read()
{
    cin.getline(S + 1, 100005);
    N = strlen(S + 1);
}

void Solve()
{
    int ans = N;
    for(int i = 1; i < N; i++)
    {
        if(S[i] != S[i + 1])
            ans = min(ans, max(i, N - i));
    }
    cout << ans << "\n";
}
int main()
{
    Read();
    Solve();
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	if (A * N > B) {
		cout << B;
	}
	else {
		cout << A * N;
	}
}

Measured memory_bytes: 256
n = gets.to_i
inputs = gets.split.map(&:to_i)
lists = []
inputs.each do |k|
  lists << k if k % 2 == 0
end
count = 0
lists.each do |i|
  count += 1 if i % 3 == 0 || i % 5 == 0
end
puts count == lists.size ? 'APPROVED' : 'DENIED'


Measured memory_bytes: 1916
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {

    static class City {
        int index;
        int freq = 0;

        public City(int index) {
            this.index = index;
        }
    }

    public static void main(String[] args) throws Exception {
        MyScanner scan = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = scan.nextInt();
        int x = scan.nextInt();
        int output = 1;
        int curr = 0;
        for (int i = 0; i < n; i++) {
            curr += scan.nextInt();
            if (curr <= x) {
                output++;
            }
        }
        out.println(output);
        out.close();
    }


    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------

}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

int main()
{
	int d,n;
	cin >> d >> n;
	int num = 1;
	for(int i = 0; i < d; i++) num *= 100;
	int ans = num*n;
	if(n == 100) ans += num;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int A=sc.nextInt();
        int B = sc.nextInt();
        if (A<B){
            int tmp = A;
            A=B;
            B=tmp;
        }
        double ans = (A+B)/2.0;
        int floor = (int)ans;
        double finalnum = ans-floor;
        if (finalnum==0){
            System.out.println(floor);
        }else{
            System.out.println("IMPOSSIBLE");
        }
    }
}


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

int main()
{
    int n;
    double x, out = 0;
    string u;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x >> u;
        if (u == "BTC")
            out += x * 380000;
        else
            out += x;
    }
    cout << out << endl;
}

Measured memory_bytes: 256
n,x=map(int,input().split())
m=2*n-1
if x==1 or x==m:
    print("No")
    exit()
if n==2:
    print("Yes")
    for i in [1,2,3]:
        print(i)
    exit()
ll=list(range(1,2*n))
if x!=2:
    l=[x-1,x,x+1,x-2]
    ll.remove(x-1)
    ll.remove(x)
    ll.remove(x+1)
    ll.remove(x-2)
else:
    l=[x+1,x,x-1,x+2]
    ll.remove(x-1)
    ll.remove(x)
    ll.remove(x+1)
    ll.remove(x+2)

ans=[]
for i in range(len(ll)):
    if i==n-2:
        ans+=l
    ans.append(ll[i])
if len(ll)==n-2:
    ans+=l
print("Yes")
for i in ans:
    print(i)



Measured memory_bytes: 14060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

const int MAX_N=1<<17;
const ll INF=(1ll<<31)-1;
//update Sum Query min
class Lz_segtree{
public:
    int n;
    ll e=INF;
    ll init=0;
    vector<ll> dat,lz;
    Lz_segtree(int n_):n(n_){
        n=1;
        while(n<n_) n*=2;
        dat.resize(n*2,INF);
        lz.resize(n*2,init);
    }
    void update_f(ll& d,ll x){
        d+=x;
    }
    ll dat_propergate(ll l,ll r){
        return min(l,r);
    }
    void lz_propergate(ll& l,ll& r,ll x){
        l+=x,r+=x;
    }
    void eval(int len,int k){
        if(lz[k]!=init) update_f(dat[k],lz[k]);
        if(len>1){
            lz_propergate(lz[k*2+1],lz[k*2+2],lz[k]);
        }
        lz[k]=init;
    }
    //range [a,b)
    void update(int a,int b,int k,int l,int r,ll x){
        eval(r-l,k);
        if(r<=a||b<=l) return;
        if(a<=l&&r<=b){
            update_f(lz[k],x);
            eval(r-l,k);
        }
        else{
            update(a,b,k*2+1,l,(l+r)/2,x);
            update(a,b,k*2+2,(l+r)/2,r,x);
            dat[k]=dat_propergate(dat[2*k+1],dat[2*k+2]);
        }
    }
    //range [a,b)
    ll query(int a,int b,int k,int l,int r){
        eval(r-l,k);
        if(r<=a||b<=l) return e;
        if(a<=l&&r<=b) return dat[k];
        else{
            ll vl=query(a,b,k*2+1,l,(l+r)/2);
            ll vr=query(a,b,k*2+2,(l+r)/2,r);
            return dat_propergate(vl,vr);
        }
    }
    void update(int a,int b,ll x){
        return update(a,b,0,0,n,x);
    }
    ll query(int a,int b){
        return query(a,b,0,0,n);
    }
};

int main(){
    int n,q,c,s,t,x;
    cin>>n>>q;
    Lz_segtree seg(n);
    seg.update(0,n,-INF);
    rep(i,q){
        cin>>c;
        if(c==0){
            cin>>s>>t>>x;
            seg.update(s,t+1,x);
        }
        else{
            cin>>s>>t;
            ll ans=seg.query(s,t+1);
            cout<<ans<<endl;
        }
    }
    return 0;
}



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

using namespace std;

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

  int A,B; cin>>A>>B;
  if (A > B) swap(A, B);

  auto a = A, b = B;
  int r = b%a;
  while (r) {
    b = a;
    a = r;
    r = b % a;
  }
  cout << (long)A*B/a << endl;

  return 0;
}


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

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
#define fcout cout<<fixed<<setprecision(10)
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
//template<typename T>void pp(T x){cout<<x<<endl;}

using namespace std;
template<typename T> void test(vector<T> v){for(int i=0;i<v.size();i++){if(i)cout<<" ";cout<<v[i];}cout<<endl;}

int main(){
    ll n;
    cin>>n;
    if(n%2==0)cout<<n<<endl;
    else cout<<n*2<<endl;
    
    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;

typedef long long int ll;

int n;
int p[1024];
int x[1024];
int maxmin[1024], minmin[1024];


int main(void){
	cin >> n;
	vector<vector<int> > c(n+1);
	vector<int> vtmp;
	for(int i=1;i<=n;i++) c[i] = vtmp;

	for(int i=2;i<=n;i++) {cin >> p[i]; c[p[i]].pb(i);}
	for(int i=1;i<=n;i++) cin >> x[i];



	for(int i=n;i>=1;i--){
		//int minminsum = 0, maxminsum = 0;
		int target = x[i];
		vector<int> rem;
		ll allsum = 0, base = 0;
		for(int j=0;j<c[i].size();j++){
			//minminsum += minmin[c[i][j]];
			//maxminsum += maxmin[c[i][j]];
			allsum += maxmin[c[i][j]] + minmin[c[i][j]];
			base += minmin[c[i][j]];
			target -= minmin[c[i][j]];
			rem.pb(maxmin[c[i][j]]-minmin[c[i][j]]);
		}
		if (target < 0) {cout << "IMPOSSIBLE" << endl; return 0;}
		int ok[5003];
		for(int j=0;j<=target;j++) ok[j] = 0;
		ok[0] = 1;
		int maxi = 0;
		for(int j=0;j<rem.size();j++){
			for(int k=target;k>=0;k--){
				if (ok[k] && k+rem[j]<=target){
					ok[k + rem[j]] = 1;
					maxi = max(maxi, k+rem[j]);
				}
			}
		}
		minmin[i] = x[i];
		maxmin[i] = allsum - (base + maxi);
		if (maxmin[i] < minmin[i]) swap(minmin[i], maxmin[i]);

		/*if (maxminsum <= x[i]){
			maxmin[i] = x[i];
			minmin[i] = minminsum;
		}else if (minminsum <= x[i]){
			maxmin[i] = maxminsum;
			minmin[i] = x[i];
		}else{
			cout << "IMPOSSIBLE" << endl; return 0;
		}*/

		//cout << i << ":" << minmin[i] << " " << maxmin[i] << endl;
	}
	cout << "POSSIBLE" << endl;

	//cout << (solve(1) ? "POSSIBLE" : "IMPOSSIBLE") << endl;

	return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <algorithm>
#define oo 987654321
#define INT long long
using namespace std;

INT n, k, x = 1, t, mx;

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>k;
    for(int i = 0 ; i < n ; i++ )
    {
        cin>>t;
        if( i == 0 ) x = t;
        x = __gcd(x, t);
        mx = max(mx, t);
    }
    if( mx < k ) cout<<"IMPOSSIBLE"<<endl;
    else if( (mx-k)%x ) cout<<"IMPOSSIBLE"<<endl;
    else cout<<"POSSIBLE"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int mod = 1E9 + 7;
const int inf = 1 << 29;

int main() {
  ll a;
  double b;
  cin >> a >> b;
  ll ib = b * 100 + 0.5;
  ll ans = a * ib / 100;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    
    unordered_map<string, int> c(n);
    rep(i, n) c[s[i]] = 0;
    rep(i, n) c[s[i]]++;

    int maxC = 0;
    for(auto kv : c) {
        maxC = max(maxC, kv.second);
    } 

    vector<string> ans;
    for(auto kv : c) {
        if (kv.second == maxC) {
            ans.push_back(kv.first);
        }
    }

    sort(all(ans));
    ans.erase(unique(all(ans)), ans.end());

    rep(i, ans.size()) put(ans[i]);

    return 0;
}

Measured memory_bytes: 31944
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        SqueezeTheCylinders solver = new SqueezeTheCylinders();
        solver.solve(1, in, out);
        out.close();
    }

    static class SqueezeTheCylinders {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            double[] r = new double[n];
            for (int i = 0; i < n; i++) {
                r[i] = in.nextDouble();
            }
            double[] center = new double[n];
            Arrays.fill(center, -1e9);
            center[0] = 0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < i; j++) {
                    center[i] = Math.max(center[i], center[j] + Math.sqrt((r[i] + r[j]) * (r[i] + r[j]) - (r[i] - r[j]) * (r[i] - r[j])));
                }
            }
            double L = 1e9, R = -1e9;
            for (int i = 0; i < n; i++) {
                //System.err.println(center[i]);
                L = Math.min(L, center[i] - r[i]);
                R = Math.max(R, center[i] + r[i]);
            }
            out.printf("%.8f\n", R - L);
        }

    }
}

Measured memory_bytes: 34608
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


signed main(){
    int R, C;
    while(cin >> R >> C, R+C){
        VI a(C);
        rep(i, 0, R) rep(j, 0, C){
            int x;
            cin >> x;
            a[j] = (x<<i)|a[j];
        }
        int ans = 0;
        rep(i, 0, 1<<R){
            int s = 0;
            rep(j, 0, C) s += max((int)__builtin_popcount(a[j]^i), R-__builtin_popcount(a[j]^i));
            chmax(ans, s);
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3148
#include <stdio.h>
#include <stdlib.h>
#define MAX 100000

typedef struct{
  int num;
  char mark;
  int c;
}Card;
 
int partition(Card *A,int p,int r);
void quicksort(Card *A,int p,int r);
void change_i(Card *A,int i,int j );

int main(){
  Card a[100000];
  int n,i,flag=0;

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf(" %c %d", &a[i].mark,&a[i].num);
    a[i].c=i;
  }
  
  quicksort(a,0,n-1);

  for(i=0; i<n; i++){
    if(a[i].num == a[i+1].num)
      if(a[i].c > a[i+1].c) flag=1;
  }

  if(flag==0) printf("Stable\n");
  else printf("Not stable\n");

  for ( i = 0; i < n; i++ ){
    printf("%c %d\n",a[i].mark,a[i].num);
  }
  return 0;
}

int partition(Card *A,int p,int r){
  int x,i,j,a;  
  x = A[r].num;
  
  i = p-1;
  for (j = p; j <= r-1; j++){
    if (A[j].num <= x){
      i = i+1;
      change_i(A,i,j);
    }
  }
  change_i(A,i+1,r);

  return i+1;
}

void quicksort(Card *A,int p,int r){
  int q;
  if (p < r){
    q = partition(A, p, r);
    quicksort(A, p, q-1);
    quicksort(A, q+1, r);
  }
}

void change_i(Card *A,int i,int j ){
  Card temp;
  temp = A[i];
  A[i] = A[j];
  A[j] = temp;
}

Measured memory_bytes: 1780
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	p := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&p[i])
	}

	swapMin := n + 1
	swapMax := 0
	swapMinIndex := 0
	swapMaxIndex := 0
	swap := false
	for i := 1; i < n; i++ {
		if p[i-1] > p[i] {
			swap = true
			if swapMin > p[i] {
				swapMin = p[i]
				swapMinIndex = i
			}
			if swapMax < p[i] {
				swapMax = p[i-1]
				swapMaxIndex = i - 1
			}
		}
	}

	if swap == false {
		fmt.Println("YES")
		return
	}

	//swap
	tmp := p[swapMinIndex]
	p[swapMinIndex] = p[swapMaxIndex]
	p[swapMaxIndex] = tmp

	for i := 1; i < n; i++ {
		if p[i-1] > p[i] {
			fmt.Println("NO")
			return
		}
	}

	fmt.Println("YES")
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    //
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt(), r = sc.nextInt();
        System.out.println(sln(l, r));
        sc.close();
    }

    static int sln(int l, int r) {
        if (r - l >= 2019) return 0;
        int res = 2019;
        for (int i = l; i < r; i++) {
            for (int j = i + 1; j <= r; j++) {
                int mod = ((j % 2019) * (i % 2019)) % 2019;
                res = Math.min(res, mod);
            }
        }
        return res;
    }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
const int H = 10, W = 1001;
int h, w, k, cnt[H], q[H], tb[H][W];
int main() {
    //freopen("in.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> h >> w >> k;
    for(int i=0; i<h; i++) {
        for(int j=0; j<w; j++) {
            char c; cin >> c;
            tb[i][j] = c-'0';
        }
    }
    int ans = h*w;
    for(int mask = 0; mask < 1<<(h-1); mask++) {
        memset(cnt, 0, sizeof(cnt));
        int c = 0;
        for(int i=0; i<h; i++) {
            q[i] = c;
            if(mask & (1<<i)) c++;
        }
        bool reset = 0, fail = 0;;
        for(int i=0, m=0; i<w; ) {
            for(int j=0; j<h; j++) {
                cnt[q[j]] += tb[j][i];
                m = max(m, cnt[q[j]]);
            }
            if(m > k) {
                if(!reset) {
                    memset(cnt, 0, sizeof(cnt));
                    m = 0, c++;
                    reset = 1;
                } else {
                    fail = 1;
                    break;
                }
            } else i++, reset = 0;
        }
        if(!fail)   ans = min(ans, c);
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) c.begin(), c.end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a <= c && c <= b ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int N,M,L,R,MIN,MAX;
  scanf ("%d %d",&N,&M);
  int M_=M;
  MAX=N;
  MIN=0;
  while(M_--)
  {
    scanf("%d %d",&L,&R);
    if (L>MIN) MIN=L;
    if (R<MAX) MAX=R;
  }
  if (MIN>MAX) printf ("%d",0);
  else
  {
    int result=(MAX-MIN+1);
    printf ("%d",result);
  } 
  return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  int n;
  cin >> n;
  vi s(n);
  rep(i,n) cin >> s[i];
  sort(all(s));
  int sum = 0;
  rep(i,n) {
    sum += s[i];
  }
  if(sum % 10 != 0) {
    cout << sum << endl;
    return 0;
  }
  rep(i,n) {
    if(s[i] % 10 != 0) {
      sum -= s[i];
      break;
    }
  }
  cout << (sum%10 == 0? 0:sum) << endl;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
min_L = 1
max_R = 1 * 10 ** 7
for i in range(M):
    L,R=map(int,input().split())
    min_L = max(L,min_L)
    max_R = min(R,max_R)

if max_R >= min_L :  
    print(max_R - min_L + 1)
else :
    print(0)

Measured memory_bytes: 9140
#include<iostream>
#include<string>

using namespace std;

int monthTable[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int date[13];
string dayTable[7] = {"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"};

void initialize(){
    date[0] = 0;
    date[1] = monthTable[1];
    for ( int i = 2; i <= 12; i++ ){
	date[i] = date[i-1] + monthTable[i];
    }
}

main(){
    initialize();
    int month, day;
    while( cin >> month >> day && month){
	cout << dayTable[(date[month-1]+day-1)%7] << endl;
    }
}

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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> x(M);
  for(int i=0;i<N;i++){
    int K;
    cin >> K;
    for(int j=0;j<K;j++){
      int a;
      cin >>a;
      x[a-1] ++;
    }
  }
  
  int ans=0;
  for(int i=0;i<M;i++){
    if(x[i]==N){
      ans++;
    }
  }
  cout << ans <<endl;
  
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

d = [0]*N
ans = 0
for i in range(N):
    a = A[i]
    l,r = i+a, i-a
    if 0 <= l < N:
        d[l] += 1
    if 0 <= r < N:
        ans += d[r]

print(ans)


Measured memory_bytes: 92672
n, v = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)
d = gets.split.map(&:to_i)
ab = Hash.new(0)
a.each do |x|
  b.each do |y|
    ab[x + y] += 1
  end
end
cd = Hash.new(0)
c.each do |x|
  d.each do |y|
    cd[x + y] += 1
  end
end
ab_keys = ab.keys.sort
cd_keys = cd.keys.sort
answer = 0
ab_keys.each do |x|
  break if x > v
  y = cd_keys.bsearch {|y| x + y >= v }
  if y && x + y == v
    answer += ab[x] * cd[y]
  end
end
p answer


Measured memory_bytes: 111408
#include<bits/stdc++.h>
using namespace std;
int main(){
    int num,box = 1;
    int count,i;
    cin >> num;
    cin >> count;
    for(i = 1; i <= num; i++){
        if (box <= count){
            box *= 2;
        }
        else{
            box += count;
        }
    }
    cout << box << endl;
}

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

int counter(int last, int p, int q, int a, int n){
	int count = 0;
	if(p < 0) return 0;
	if(p == 0) return 1;
	if(n == 0){
		if(p == 0) return 1;
		else return 0;
	}else{
		for(int i = last; a / i > 0; i++){
			int y = i * q;
			int p2 = p * i - q;
			count += counter(i, p2, y, a / i, n - 1);
		}
	}
	return count;
}

int main(){
	int p, q, a, n;
	while(cin >> p >> q >> a >> n && (p || q || a || n)){
		cout << counter(1, p, q, a, n) << endl;
	}
	return 0;
}

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

using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const int inf = 1e9+7;
const int mod = 1e9+7;

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

    int ans=0;

    rep2(i,1,n){
        int a;
        cin>>a;

        if(i%2!=0&&a%2!=0)ans++;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 3616