akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#include <queue>

using namespace std;

void preambule() {
  cin.tie(0);
  cout.precision(16);
  cout << fixed;
}

int a;
int b;

void input() {
  cin >> a >> b;
}

void solve1() {
  int ans = 0;

  if (a >= 6 && a <= 12) {
    ans = b / 2;
  } else if (a > 12) {
    ans = b;
  }

  cout << ans << '\n';
}

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  preambule();
  input();
  solve1();
}


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

int	main()
{
  string	str;
  int		c = 0;
  
  cin >> str;
  for(int i = 0; i < 3; i++)
    if (str.at(i) == '1')
      c++;
  cout << c << endl;
  return (0);
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for(int i=a;i<b;i++)
#define repds(i,a,b) for(int i=a+1;i<=b;i++)
#define rep(i,N) repd(i,0,N)
#define reps(i,N) repds(i,0,N)
#define debug(x) if(isDebugMode) cout<<#x<<"="<<x<<","
#define debugarr(arr,N,M){if(isDebugMode) rep(i,N+1){rep(j,M+1)\
	{if(arr[i][j]==INF)printf(" INF");\
		else printf(" %3d",arr[i][j]);} cout<<endl;}}
#define pb push_back
#define pob pop_back
#define cint(a) int a;cin>>a
#define cint2(a,b) int a,b;cin>>a>>b
#define cint3(a,b,c) int a,b,c;cin>>a>>b>>c
typedef long long ll;
typedef pair<int,int> P;
const int INF=100000000;
const int dx[4]={ 0, 1, 0,-1};
const int dy[4]={ 1, 0,-1, 0};

bool isDebugMode=true;
//--------------------------------------//
int n;
int s[100000];
int ans[100000];
int c;

void print(){
	rep(i,n){
		if(ans[i]==1) cout<<"S";
		else  cout<<"W";
	}
	cout<<endl;
}

int solve(int a,int b){
	ans[0]=a,ans[1]=b;
	repd(i,2,n){
		if((s[i-1]+ans[i-1])%2==0) ans[i]=ans[i-2];
		else  ans[i]=ans[i-2]^1;
	}
	if((s[n-1]+ans[n-1])%2==0&&ans[n-2]==ans[0]){ 
		if((s[0]+ans[0])%2==0&&ans[n-1]==ans[1]||(s[0]+ans[0])%2==1&&ans[n-1]!=ans[1]) 
		{
			print();
			return 0;
		}
	}
	else if((s[n-1]+ans[n-1])%2==1&&ans[n-2]!=ans[0])
		if((s[0]+ans[0])%2==0&&ans[n-1]==ans[1]||(s[0]+ans[0])%2==1&&ans[n-1]!=ans[1]) 
		{
			print();
			return 0;
		}
	c++; if(c==4) cout<<"-1"<<endl;return 1;
}

int main(){
	cin>>n;
	rep(i,n) {
		char c;
		cin>>c;
		s[i]=(c=='o')?1:0;
	}
	if(solve(1,1)==0) return 0;
	if(solve(1,0)==0) return 0;
	if(solve(0,1)==0) return 0;
	if(solve(0,0)==0) return 0;
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rp(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
#define PI 3.1415926535898

int main(){
    double a,b,x;
    cin >> a >> b >> x;
    double t=2*(a*a*b-x)/a/a/a;
    if(x>=a*a*b/2){
        cout <<fixed<<setprecision(10)<< 180*atan(t)/PI << endl;
    }
    else{
        cout <<fixed<< setprecision(10)<< 90-180/PI*atan(2*x/a/b/b) << endl;
    }
    return 0;
}

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

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

  int64_t res=0;
  for (int i = 1; i < N+1; i++) {
    if (i%3!=0 && i%5!=0) res+=i;
  }
    cout << res << endl;

}

Measured memory_bytes: 3632
my $N = <STDIN>;
if($N==1){print "$N";exit;}
my $sum =0;
my %del;
for(my $i=$N;$i>0;$i--){
 $count = int($N /$i);
 $del{$i} = ($count*$count*$count);
}
for(my $i=$N;$i>1;$i--){
 $del{1}=$del{1} - $del{$i};
 for(my $j=2;$j<=sqrt($i);$j++){
    if( ($i%$j == 0) ){
        $del{$j}= $del{$j} - $del{$i};
        if( $j ==($i/$j)){next;}
        $del{$i/$j}= $del{$i/$j} - $del{$i};
    }
 }
 $sum = $sum + $i*$del{$i};
 #print "i$i del$del{$i} $sum\n";
}
$sum = $sum + $del{1};
print "$sum";
exit;

Measured memory_bytes: 4828
// When you are hungry for something and you're determined and you're focused 
// and you're committed to something it's hard to surrender, isn't it?

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define ll long long 
#define int ll
#define mod 1000000007
#define mod1 1000000006
#define modi 998244353
#define setbit(x) __builtin_popcount(x)
#define fff(i,n) for(int i=0;i<n;i++)
#define fab(i,a,b) for(int i=(a);i<(b);i++)
#define ff first
#define ss second
#define pb push_back
vector<ll> vi[300005];
int color[100005];
ll pa[500005];
ll si[500005];
#define pb push_back
bool visi[1000005]={false};
bool is[100005];
ll fac[10000001];
ll prime[400005];
ll bit[100005];
const long double eps = 1.0e-14;      // allowable error
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
void fact(){
    fac[0]=1;
    for(int i=1;i<=10000000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    return ;
}
void sieve(){
    prime[0]=0;
    prime[1]=0;
    for(int i=2;i<400005;i++){
        prime[i]=1;
    }
    for(int i=2;i*i<400005;i++){
        if(prime[i]==1){
            for(int j=i*i;j<400005;j+=i){
                prime[j]=0;
            }
        }
    }
    
}
 
ll power(ll n , ll p ){
    if(p==0)
        return 1;
    
    ll res = power((n*n)%mod,p/2);
    if(p%2==1)
        res = (n*res)%mod;
    
    return res;
}
 
 
void upd(ll i,ll val,ll n) {
    for(;i<=n;i+=i&(-i))
        bit[i]+=val;
}
 
ll qry(ll i) {
    ll sum=0;
    for(;i>0;i-=i&(-i))
        sum+=bit[i];
    return sum;
}
 
 
ll fin(ll u) {
    if(pa[u]==u)
        return u;
    return fin(pa[u]);
}
 
void uni(ll u,ll v) {
    ll p1=fin(u);
    ll p2=fin(v);
    if(p1==p2)
        return;
    if(si[p1]<si[p2])
        swap(p1,p2);
    si[p1]+=si[p2];
    pa[p2]=p1;
    return;
}

int log(int x) {
    int i;
    for(i=0;(1<<i)<=x;i++);
    return i;
}

vector<int> osci(vector<int> v) {
	vector<int> v1;
	int n=v.size();
	int i=0,j=n-1;
	for(int k=0;k<n;k++) {
		if(k%2==0)
			v1.pb(v[i++]);
		else
			v1.pb(v[j--]);
	}
	reverse(all(v1));
	return v1;
} 
 
int32_t main() {
    fio
	cout << fixed << setprecision(15);
    
    int a,b;
    cin >> a >> b;// >> c >> x;
    string s;cin >> s;
    int n=s.size();
    
    int c=0;
    
    fff(i,n) {
        if(s[i]=='-') {
            if(c!=a) {
                cout << "No";
                return 0;
            }
            c=0;
        }
        else
        c++;
    }
    
    if(c!=b) {
        cout << "No";
        return 0;
    }
    cout << "Yes";

	return 0;
    
}

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

main()
{
  int n;
  int t, x, y;
  int old_x = 0, old_y = 0, old_t = 0;
  
  int f = 1;

  cin >> n;
  for ( int i = 0; i < n ; ++i) {
    cin >> t >> x >> y;

    int k = abs(x-old_x) + abs(y-old_y);
    if ( k > t-old_t )
      f = 0;

    if ( k%2 != (t-old_t)%2 )
      f = 0;

    old_t = t;
    old_x = x; old_y = y;
  }

  if(f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return (0);
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
using namespace std;

int W, H, N;
int X1[1000], X2[1000], Y1[1000], Y2[1000];
bool fld[6000][6000];
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int compress(int *x1, int *x2, int w){
	vector<int> xs;
	
	for(int i = 0; i < N; i++){
		for(int d = -1; d <= 1; d++){
			int tx1 = x1[i]+d, tx2 = x2[i]+d;
			if(0 <= tx1 && tx1 <= w) xs.push_back(tx1);
			if(0 <= tx2 && tx2 <= w) xs.push_back(tx2);
		}
	}
	sort(xs.begin(), xs.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	
	for(int i = 0; i < N; i++){
		x1[i] = find(xs.begin(), xs.end(), x1[i]) - xs.begin();
		x2[i] = find(xs.begin(), xs.end(), x2[i]) - xs.begin();
	}
	return xs.size()-1;
}

void solve(){
	W = compress(X1, X2, W);
	H = compress(Y1, Y2, H);
	
	memset(fld, 0, sizeof(fld));
	for(int i = 0; i < N; i++){
		for(int y = Y1[i]; y <= Y2[i]; y++){
			for(int x = X1[i]; x <= X2[i]; x++){
				fld[y][x] = true;
			}
		}
	}
	
	int ans = 0;
	for(int y = 0; y <= H; y++){
		for(int x = 0; x <= W; x++){
			if(fld[y][x]) continue;
			ans++;
			
			queue<pair<int, int> > que;
			que.push(make_pair(x,y));
			while(!que.empty()){
				int sx = que.front().first, sy = que.front().second;
				que.pop();
				
				for(int i = 0; i < 4; i++){
					int tx = sx+dx[i], ty = sy+dy[i];
					if(tx < 0 || W < tx || ty < 0 || H < ty) continue;
					if(fld[ty][tx]) continue;
					que.push(make_pair(tx,ty));
					fld[ty][tx] = true;
				}
			}
		}
	}
	
	printf("%d\n", ans);
}

int main(){
	while(scanf("%d%d", &W, &H), W||H){
		W *= 2; H *= 2;
		scanf("%d", &N);
		for(int i = 0; i < N; i++){
			scanf("%d%d%d%d", &X1[i], &Y1[i], &X2[i], &Y2[i]);
			X1[i] *= 2; Y1[i] *= 2; X2[i] *= 2; Y2[i] *= 2;
		}
		solve();
	}
}

Measured memory_bytes: 36248
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
 
template<class T> inline bool change_min(T& a, T b) {
	if (a > b) {
    	a = b;
        return 1;
    } else {
    	return 0;
    }
}
 
const long H_MAX = 9999999999;
const int n = 100001;
 
int N;
long long h[n];
 
long long dp[n];
 
int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) cin >> h[i];
 
    for (int i = 0; i < n; i++) {
    	dp[i] = H_MAX;
    }
 
    dp[0] = 0;
 
    for (int i = 1; i < N; ++i) {
        change_min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1){
        	change_min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
        }
    }
 
    cout << dp[N-1] << endl;
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define END(x) cout << x << endl; exit(0);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, minimum, maximum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int main() {
    cin >> s;
    REP(i, 0, s.size()) {
        if (i % 2 == 1) {
            if (!(s.at(i) == 'L' || s.at(i) == 'U' || s.at(i) == 'D')) {
                END("No")
            }
        } else {
            if (!(s.at(i) == 'R' || s.at(i) == 'U' || s.at(i) == 'D')) {
                END("No")
            }
        }
    }
    MSG("Yes")
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define PI acos(-1)
#define sz 100010
#define RUN_FAST ios::sync_with_stdio(false);
using namespace std;

int main()
{
    RUN_FAST; cin.tie(nullptr);
    int a, b, c;
    cin >> a >> b >> c;
    if (a==b && b==c) cout << "No" << endl;
    else if (a!=b && b!=c && c!=a) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3644
#include<stdio.h>
int main()
{
	int n,a[100],i,j,c;
	while(scanf("%d",&n),n)
	{
		for(i=0; i<n; ++i) scanf("%d",&a[i]);
		for(c=i=0; i<n; ++i) for(j=1; j<n; ++j) if(a[j-1]>a[j]) a[j-1]^=a[j],a[j]^=a[j-1],a[j-1]^=a[j],++c;
		printf("%d\n",c);
	}
	return 0;
}

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


const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

//a^nを計算する
long long modpow(long int a, long int n, long int mod) {
    long int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res;
}

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main(){
    COMinit();
    ll X, Y; cin >> X >> Y;
    if(Y < X){
        ll temp = X;
        X = Y;
        Y = temp;
    }
    ll n1 = Y-X; // 余分に多い数
    if((X-n1) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    ll n2 = (X-n1) / 3; // 共通数
    cout << COM(2*n2+n1, n2) << endl;
    
}

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

int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    ll ans = 0;
    if (a <= k)
        ans += a, k -= a;
    else
        ans = k, k = 0;
    k -= b;
    if (k > 0) ans -= k;

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


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<int, int> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };


int main() {

	ll n, m;
	cin >> n >> m;
	ll ans = 0;
	if (n * 2 > m) {
		if (m % 2 == 0) {
			ans = m / 2;
			cout << ans << endl;
		}
		else {
			ans = (m - 1) / 2;
			cout << ans << endl;
		}
	}
	else if (n * 2 == m) {
		ans = n;
		cout << ans << endl;
	}
	else if (n * 2 < m) {
		ans = n + (m - n * 2) / 4;
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
template<class Type> Type read() {
	Type a;
	bool b;
	unsigned char c;
	while(c=getchar()-48, (c>9)&(c!=253));
	for(a=(b=c==253)?0:c; (c=getchar()-48)<=9; a=a*10+c);
	return b?-a:a;
}
int (*rd)()=read<int>;
typedef unsigned u32;
typedef long long s64;
typedef unsigned long long u64;

const int N=6005;
int a[N], b[N];
char s[N], cur[N], f[N][N];
int main() {
	int n, m=0;
	assert(scanf("%d%s", &n, s)==2);
	for(int l=0, r; l<2*n; l=r, ++m) {
		int na=0, nb=0;
		for(r=l; r==l||na!=nb; ++r) (s[r]=='a'?a[na++]:b[nb++])=r;
		if(s[l]=='a') {
			char *p=f[m];
			for(int i=0, j=l-1, len=0; i<na; ++i) if(a[i]>j) *p++='a', *p++='b', j=b[i];
		} else {
			for(int i=na; i--; ) {
				memset(cur, 0, r-l);
				for(int j=i; j<na; ++j) cur[a[j]-l]='a', cur[b[j]-l]='b';
				*std::remove(cur, cur+r-l, 0)=0;
				if(strcmp(cur, f[m])>0) strcpy(f[m], cur);
			}
		}
	}
	for(int i=m; i--; ) {
		strcat(f[i], f[i+1]);
		if(strcmp(f[i+1], f[i])>0) strcpy(f[i], f[i+1]);
	}
	puts(f[0]);
	return 0;
}


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

int main() {

    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int k; cin >> k;
    cout << a[k-1] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		sc.close();
		if(a.length() > b.length()) {
			System.out.println("GREATER");
		}else if(a.length() < b.length()) {
			System.out.println("LESS");
		}
		else {
			for(int i = 0 ; i < a.length(); i++) {
				if(Integer.parseInt(a.substring(i, i + 1)) > Integer.parseInt(b.substring(i, i + 1))) {
					System.out.println("GREATER");
					break;
				}else if(Integer.parseInt(a.substring(i, i + 1)) < Integer.parseInt(b.substring(i, i + 1))) {
					System.out.println("LESS");
					break;
				}else {
					if(i == a.length() - 1) {
						System.out.println("EQUAL");
						break;
					}else {
					continue;
					}
				}
			}
		}
	}
}

Measured memory_bytes: 23508
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PI 3.1415926535897932384626433832795
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 998244353;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct chash {
    int operator()(int x) const { return x ^ RANDOM; }
};
string toString(long long x)
{
stringstream ss;
ss << x;
string str = ss.str();
return str;
}
long long fastpow(long long x,long long k)
{
    if(!k)
        return 1;
    if(k & 1)
        return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
    long long ans = fastpow(x,k/2);
    ans %= MOD;
    ans *= ans;
    ans %= MOD;
    return ans;
}
long long sumF(long long x)
{
    int s = 0;
    while(x)
        s += x%10,x /= 10;
    return s;
}
int main()
{
    IO;
    long long n;
    cin >> n;
    vector<long long> ff(5);
    for(int i = 0;i < 5;i++)
        cin >> ff[i];
    long long minN = 1e18;
    long long highest = 0;
    for(int i = 0;i < 5;i++)
    {
        minN = min(minN,ff[i]);
        highest = max(highest,i + (n + minN - 1) / minN);
    }
    cout << highest;
    return 0;
}


Measured memory_bytes: 384
from heapq import heappush, heappop
inputs = lambda: map(int, raw_input().split())
n, q = inputs()
n += 1
que = [(0, 1, -1)]
data = [0] * n
T = [-1] * n
for t in xrange(q):
    a, v = inputs()
    data[a] += v
    T[a] = t

    heappush(que, (-data[a], a, t))
    v, k, p = que[0]
    while T[k]!=p:
        heappop(que)
        v, k, p = que[0]
    print k, -v

Measured memory_bytes: 37888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int a,b,ans = 1; cin>>a>>b;
	if(b==1)cout<<0<<endl;
	else{
		int aux = a;
		while(a<b){
			a+=aux;
			a--;
			ans++;
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 1005;
int h, w, K;
char a[maxn];
int sum[11][maxn], pos[11], cnt[11], chk[11];
int main() {
	ios::sync_with_stdio(false);
	cin >> h >> w >> K;
	for(int i = 1; i <= h; ++i) {
		cin >> a;
		for(int j = 1; j <= w; ++j)
			sum[i][j] = sum[i - 1][j] + (a[j - 1] == '1');
	}
	int tot, ans = INF, cur;
	for(int i = 0; i < (1 << h); ++i) {
		memset(cnt, 0, sizeof(cnt));
		tot = 0, cur = 0;
		for(int j = 0; j < h - 1; ++j) {
			if((i >> j) & 1) 
				pos[++tot] = j + 1;
		}
		cur = tot, pos[++tot] = h;
		bool flag = false;
		for(int j = 1; j <= w; ++j) {
			for(int k = 1; k <= tot; ++k) {
				chk[k] = sum[pos[k]][j] - sum[pos[k - 1]][j];
				if(chk[k] > K) {
					flag = true;
					break;
				}
			}
			if(flag) break;
			for(int k = 1; k <= tot; ++k) {
				cnt[k] += chk[k];
				if(cnt[k] > K) {
					for(int l = 1; l <= tot; ++l)
						cnt[l] = chk[l];
					cur++;
					break;
				}
			}
		}
		if(flag) continue;
		ans = min(ans, cur);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int 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);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> M;
  deque<lli>que;
  UnionFind uf(N);
  Vec(G,pint,M,pint(0,0));
  rep(i,0,M)cin >> G[i].first >> G[i].second;
  Rev(G);
  num=N*(N-1)/2;
  que.push_front(num-0);
  rep(i,0,M-1){
    sum=0;
    if(uf.find(G[i].first-1)!=uf.find(G[i].second-1))num-=uf.size(G[i].first-1)*uf.size(G[i].second-1);
    uf.unite(G[i].first-1,G[i].second-1);
    que.push_front(num);
  }
  while(!que.empty()){
    auto v=que.front();que.pop_front();
    Out(v);
  }
}

Measured memory_bytes: 3868
N = int(input())
list = [[0]*9,[0]*9,[0]*9,[0]*9,[0]*9,[0]*9,[0]*9,[0]*9,[0]*9]
for i in range(N):
    s = i + 1
    if s%10 != 0:
        S = str(s)
        list[int(S[0])-1][int(S[-1])-1] = list[int(S[0])-1][int(S[-1])-1] + 1
a = 0
for i in range(9):
    for j in range(9):
        a = a + list[i][j]*list[j][i]


print(a)

Measured memory_bytes: 3064
#include <stdio.h>
#include<math.h>

int main(void)
{
	double t,v,y,n;

	while (scanf("%lf", &v) != EOF) {
		t = v / 9.8;
		y = 4.9 * t * t;
		n = (y + 5) / 5.0;

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

Measured memory_bytes: 632
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define REP_AB(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define REP_IN(i, n, x) for (ll i = 0; i < n; i++)in>>x;
#define REP_OUT(i, n, x) for (ll i = 0; i < n; i++)out<<x<<endl;
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
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 end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N;
    in >> N;
    vector<ll> D(N);
    REP(i, N){
        in >> D[i];
    }
    SORT(D);
    //REP_OUT(i, N, D[i])
    out << D[N/2]-D[N/2-1] << endl;


}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            Console.WriteLine(Math.Abs(a[2] - a[0]) <= a[3] || (Math.Abs(a[1] - a[0]) <= a[3] && Math.Abs(a[2] - a[1]) <= a[3]) ? "Yes" : "No");
        }
    }
}



Measured memory_bytes: 13268
#include <iostream>

using namespace std;

int main()
{
   string S;cin>>S;
   if(S=="Sunny")
   {
       cout<<"Cloudy"<<endl;
       return 0;
   }else if(S=="Cloudy")
   {
       cout<<"Rainy"<<endl;
       return 0;
       
   }else if(S=="Rainy")
   {
       cout<<"Sunny"<<endl;
       return 0;
       
   }
  
   
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
	int n;
	while(cin >> n,n){
		//dice = {u,l,r,d};
		int dice[5] = {5,4,3,2,1}, res = 1;
		while(n--){
			string siji;
			cin >> siji;
			int virdice[5] = {0};
			memcpy(virdice,dice,sizeof(dice));
			if(siji == "North" || siji == "South"){
				int zero = virdice[4], three = 7 - virdice[4];
				dice[4] = siji=="North"?dice[3]:dice[0];
				dice[0] = siji=="North"?zero:three;
				dice[3] = siji=="North"?three:zero;
			}
			if(siji == "East" || siji == "West"){
				int one = 7 - virdice[4],two = virdice[4];
				dice[4] = siji=="East"?dice[1]:dice[2];
				dice[1] = siji=="East"?one:two;
				dice[2] = siji=="East"?two:one;
			}
			if(siji == "Left"){
				dice[0] = virdice[2];
				dice[1] = virdice[0];
				dice[2] = virdice[3];
				dice[3] = virdice[1];
			}
			if(siji == "Right"){
				dice[0] = virdice[1];
				dice[1] = virdice[3];
				dice[2] = virdice[0];
				dice[3] = virdice[2];
			}
			//cout << center << endl;
			//for(int i=0;i<4;i++){
			//cout << dice[i];
			//}
			//cout << "\n";
			res += dice[4];
		}
		cout << res << endl;
	}
}

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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#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; }

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

    vector<vector<ll> > dp(N.size(), vector<ll>(2, 0) );

    int top = N[0]-'0';
    // 0ならNぴったし
    dp[0][0] = top;
    dp[0][1] = top-1;

    REP(i, 1, N.size())
    {
        int key = N[i]-'0';

        chmax(dp[i][0], dp[i-1][0]+key);
        chmax(dp[i][1], dp[i-1][1]+9);
    }

    /*
    rep(i,dp.size())
    {
        rep(j, dp[i].size()) cout << dp[i][j] << " ";
        cout << endl;
    }
    */
    cout << max(dp[dp.size()-1][0], dp[dp.size()-1][1]) << endl;
}


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

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


// import here

int main(){
    LL n;
    cin >> n;
    vector<LL> a(n);
    for(LL i = 0; i < n; ++i){
        cin >> a[i];
    }
    LL ans = 100*100*100;
    for(LL p = 1; p <= 100; ++p){
        LL val = 0;
        for(LL i = 0; i < n; ++i){
            val += (p-a[i])*(p-a[i]);
        }
        ans = min(ans, val);
    }

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



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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

struct Edge{
	int src,dst;
	Edge(){}
	Edge(int s,int d):src(s),dst(d){}
};
typedef vector<vector<Edge>> Graph;

inline int clz(uint x)
{
	int i=0;
	if(!(x&0xffff0000)) i+=16,x<<=16;
	if(!(x&0xff000000)) i+=8,x<<=8;
	if(!(x&0xf0000000)) i+=4,x<<=4;
	if(!(x&0xc0000000)) i+=2,x<<=2;
	if(!(x&0x80000000)) i+=1,x<<=1;
	return i+!x;
}

struct LCA{
	vi ds;
	vvi ps;
	LCA(const Graph& g,int root):ds(g.size()),ps(32-clz(g.size()),vi(g.size(),-1)){
		DFS(g,-1,root,0);
		rep(i,ps.size()-1) rep(j,ps[i].size())
			ps[i+1][j]=ps[i][j]==-1?-1:ps[i][ps[i][j]];
	}
	void DFS(const Graph& g,int p,int v,int depth){
		ds[v]=depth;
		ps[0][v]=p;
		for(auto e:g[v]) if(e.dst!=p)
			DFS(g,e.src,e.dst,depth+1);
	}
	int Find(int a,int b){
		if(ds[a]>ds[b]) swap(a,b);
		rep(i,ps.size())
			if(ds[b]-ds[a]>>i&1)
				b=ps[i][b];
		if(a==b) return a;
		per(i,ps.size())
			if(ps[i][a]!=ps[i][b])
				a=ps[i][a],b=ps[i][b];
		return ps[0][a];
	}
};

int main()
{
	for(int n;cin>>n && n;){
		Graph g(n);
		rep(u,n){
			int k; cin>>k;
			rep(i,k){
				int v; cin>>v;
				g[u].emplace_back(u,v);
				g[v].emplace_back(v,u);
			}
		}
		LCA lca(g,0);
		int q; cin>>q;
		rep(_,q){
			int u,v; cin>>u>>v;
			cout<<lca.Find(u,v)<<endl;
		}
	}
}

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

const int MAXN = 100005;

int n;

inline int sgn(int i)
{ return i < 0 ? -1 : i > 0; }

int a[MAXN];

struct sta {
	int last, op;
	sta()
	{ op = -2;}
	inline bool push(int x)
	{
		if (op == -2) {
			last = x;
			op = 0;
			return 1;
		} else if (op == 0) {
			op = sgn(x-last), last = x;
			return 1;
		} else if (op == 1) {
			if (x-last >= 0) return last = x, 1;
			else return 0;
		} else if (op == -1) {
			if (x-last <= 0) return last = x, 1;
			else return 0;
		} else throw;
	}
};

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}
	for (int i = 1; i <= n; i++) cin >> a[i];
	sta cur;
	int cnt = 1;
	for (int i = 1; i <= n; i++) {
		if (!cur.push(a[i])) 
			cnt++, cur = sta(), cur.push(a[i]);
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
	ll n;
	cin >> n;
	ll ans = 0;
	for(ll i = 1ll; i * i <= n; i++) {
		ans = i * i;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;
const int MOD = 1000000007; // 計算してからmodで割る ans = (ans * a) % mod
#define int long long
template <typename T = long long > T in () { T x; cin >> x; return(x);}
// int a = in() のように使うlong long以外の型の時はstirng s = in<string>()のように型を指定する

signed main(void){
    int n; cin >> n;
    vector<int> num(n);
    set<int> appeared;
    REP(i, n){
        cin >> num[i];
    }
    int ans = INF;
    for(int i = -100; i <= 100; i++){
        int tmp = 0;
        REP(j, n) tmp += pow(num[j] - i, 2);
        ans = min(ans, tmp);
    }

    cout << ans;
    
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <numeric>
using namespace std;

int main()
{
  int s;
  cin>>s;
  for(int i=0;i<1000000;i++){
    if(s==4 || s==2 || s==1){
      cout<<i+4<<endl;
      break;
    }
    if(s%2==0){
      s/=2;
    }else{
      s*=3;
      s+=1;
    }
  }
}


Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))
L.sort()
from numba import njit, jit
from itertools import combinations


# @jit
# def solve():
#     ans = 0
#     for a, b, c in combinations(L, r=3):
#         ans += a + b > c
#     return ans

@njit
def solve(L):
    ans = 0
    for i in range(N - 2):
        a = L[i]
        for j in range(i + 1, N - 1):
            b = L[j]
            for k in range(j + 1, N):
                ans += a + b > L[k]
    return ans


print(solve(L))


Measured memory_bytes: 111304
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int ans = K;
    rep(i, N-1) ans *= K-1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P = pair<int,int>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF =1001001001;

int dp[100005];
vector<int> dist[100005];

int rec(int i)
{
   if(dp[i] != -1) return dp[i];
   int res = 0;
   for(auto a : dist[i])
   {
      res = max(rec(a)+1,res);
   }
   return dp[i] = res;
}

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

   rep(i,m)
   {
      int x, y;
      cin >> x >> y;
      --x; --y;
      dist[x].push_back(y);
   }

   rep(i, 100005) dp[i] = -1;

   int ans = 0;
   rep(i,n)
   {
      ans = max(rec(i), ans);
   }
   cout << ans << endl;

}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=(int)(n);i++)

template <class T> inline bool chmax(T &a,T b){
  if(a < b){
    a = b;
    return true;
  }
  else{
    return false;
  }
}
using namespace std;
int main(){
  int N,W;
  cin >> N >> W;
  int w[110],v[110];
  long long dp[110][110000];
  rep(i,N){
    cin >> w[i] >> v[i];
  }

  rep(i,N){
    rep(j,W){
      if(j >= w[i]){
        chmax(dp[i][j],dp[i-1][j - w[i]] + v[i]);
      }
      chmax(dp[i][j],dp[i-1][j]);
    }
  }
  cout << dp[N][W] << endl;
}

Measured memory_bytes: 88320
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

ans1=0
ans2=0
for i in range(n):
  #print(ans)
  if b[i]>a[i]:
    b[i]-=a[i]
    ans1+=a[i]
    a[i]=0
  else:
    a[i]-=b[i]
    ans1+=b[i]
    b[i]=0
  if b[i]>a[i+1]:
    b[i]-=a[i+1]
    ans1+=a[i+1]
    a[i+1]=0
  else:
    a[i+1]-=b[i]
    ans1+=b[i]
    b[i]=0
for i in range(n-1,-1,-1):
  #print(ans)
  if b[i]>a[i+1]:
    b[i]-=a[i+1]
    ans2+=a[i+1]
    a[i+1]=0
  else:
    a[i+1]-=b[i]
    ans2+=b[i]
    b[i]=0
  if b[i]>a[i]:
    b[i]-=a[i]
    ans2+=a[i]
    a[i]=0
  else:
    a[i]-=b[i]
    ans2+=b[i]
    b[i]=0
print(max(ans1,ans2))

Measured memory_bytes: 82148
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x) - 1 * 100);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>

using namespace std;
int n, m;
int a[200000];
int b[200000];
int vstd[200000];
int main(void) {
	cin >> n >> m;
	unordered_set<int> v;
	unordered_set<int> v2;
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i];
		b[i];
		if (b[i] == n)
			v.insert(a[i]);
		if (a[i] == 1)
			v2.insert(b[i]);
	}
	for (auto e2 : v2) {
		if (v.find(e2) != v.end()) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9

using namespace std;
typedef long long int lli;
typedef long long ll;

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

    int odd, even;
    if(k % 2 == 0){
        odd = k/2;
        even = k/2;
    }
    else{
        odd = k/2+1;
        even = k/2;
    }

    cout << odd*even << endl;
}


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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define MOD 1000000007

int main()
{
  string s;cin>>s;
  vector<vector<ll>> dp(3,vector<ll>(s.size()+1,0));
  int i;
  ll pat=1;
  for(i=s.size()-1;i>=0;i--)
  {
    if(s[i]=='?')
    {
      dp[0][i]=(dp[0][i+1]*3+pat)%MOD;
      pat=(pat*3)%MOD;
    }
    else if(s[i]=='C')dp[0][i]=(dp[0][i+1]+pat)%MOD;
    else dp[0][i]=dp[0][i+1];
  }
  for(i=s.size()-2;i>=0;i--)
  {
    if(s[i]=='?')
    {
      dp[1][i]=(dp[1][i+1]*3+dp[0][i+1])%MOD;
    }
    else if(s[i]=='B')dp[1][i]=(dp[1][i+1]+dp[0][i+1])%MOD;
    else dp[1][i]=dp[1][i+1];
  }
  for(i=s.size()-3;i>=0;i--)
  {
    if(s[i]=='?')
    {
      dp[2][i]=(dp[2][i+1]*3+dp[1][i+1])%MOD;
    }
    else if(s[i]=='A')dp[2][i]=(dp[2][i+1]+dp[1][i+1])%MOD;
    else dp[2][i]=dp[2][i+1];
  }
  cout<<dp[2][0]<<endl;
}


Measured memory_bytes: 3584
#!/usr/local/gnu/bin/bash
read s
read t
s=`echo $s | fold -1 | sort | tr -d "\n"`
t=`echo $t | fold -1 | sort -r | tr -d "\n"`
f=`echo $s $t | tr ' ' '\n' | sort | head -1`
[ $s = $f -a $s != $t ] && echo Yes || echo No

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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

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

int main()
{
  ll A[3];
  cin >> A[0] >> A[1] >> A[2];
  ll cnt5 = 0;
  ll cnt7 = 0;
  rep(i, 0, 3){
    if (A[i] == 5)
    {
      cnt5++;
    }
    if (A[i] == 7)
    {
      cnt7++;
    }
  }
  if (cnt5 == 2 && cnt7 == 1)
  {
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF317
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var sr = new InputReader(Console.In);
            //var sr = new InputReader(new StreamReader("input.txt"));
            var task = new Task();
            using (var sw = Console.Out)
            //using (var sw = new StreamWriter("output.txt"))
            {
                task.Solve(sr, sw);
                //Console.ReadKey();
            }
        }
    }

    internal class Task
    {
        public void Solve(InputReader sr, TextWriter sw)
        {
            var n = sr.NextInt32();
            var x = 0L;
            var y = 0L;
            for (var i = 1; i <= n; i++) {
                if (i % 15 == 0) {
                    y += 200;
                }
                x += 800;
            }

            sw.WriteLine(x - y);
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(NextString());
    }

    public long NextInt64()
    {
        return Int64.Parse(NextString());
    }

    public string[] NextSplitStrings()
    {
        return NextString()
            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
            .Select(s => func(s, CultureInfo.InvariantCulture))
            .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
            str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();
            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))  
#define lli long long int
#define ll long long 
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second 
#define LB lower_bound
#define UB upper_bound
#define BS binary_search
#define pii pair<lli,lli>
const long long int mod=1000000009;
//const long long int mod=998244353;
const long double PI=3.141592653589793;
const long long int inf=1e18;
const long long int inf2=LLONG_MAX;
#define setBitCount(x) __builtin_popcountll(x)
#define all(a) (a).begin(), (a).end()
#define all_r(a) (a).rbegin(), (a).rend()
lli gcd(lli a,lli b)
{
    if(b==0)
    return a;
    else
    return gcd(b,a%b);
}
// calculating (x^y)%p
lli power(lli x,lli y,lli p)
{
    lli res = 1;      
    x = x % p;  
    while (y > 0)
    {
        if (y & 1) //y is odd  
        res = (res*x) % p;
        y = y>>1; 
        x = ( (x%p)*(x%p) )% p;  
    }
    return res%p;
}
// calculating modular inverse using fermat little theorem
lli modInverse(lli n,lli p) 
{
    return power(n, p-2, p)%p;
}

// policy based data structures !!
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
// s.order_of_key (k) : Number of items strictly smaller than k
// *(s.find_by_order(k)) : K-th element in a set (counting from zero)

void solve()
{
   lli n;
   cin>>n;
   
   lli a[n+5];
   for(lli i=1;i<=n;i++)
   cin>>a[i];
   
   lli dp[n+5];
   mem(dp,0);
   dp[1]=0;
   dp[2]=abs(a[1]-a[2]);
   
   for(lli i=3;i<=n;i++)
   {
      dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
   }
   cout<<dp[n];
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    lli T;
    //cin>>T;
    T=1;
    while(T--)
    {
        solve();
    }




    return 0;
}

Measured memory_bytes: 1792
import itertools

n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))

seq = []
for i in range(n):
    seq.append(i+1)
per = list(itertools.permutations(seq))

for i in range(len(per)):
    if per[i]==p:
        a = i+1
    if per[i]==q:
        b = i+1

print(abs(a-b))


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

const int mxN = 1e5 + 5;
int N, mod;
vector<int> adj[mxN];
ll dp[mxN], ans[mxN];

void dfs_one(int u, int p) {
	dp[u] = 1;
	for (int v : adj[u]) {
		if (v == p) {
			continue;
		}
		dfs_one(v, u);
		dp[u] = dp[u] * dp[v] % mod;
	}
	dp[u] = (dp[u] + 1) % mod;
}

void dfs_two(int u, int p, ll ways_now) {
	vector<ll> pref, suf;
	pref.push_back(1);
	for (int v : adj[u]) {
		if (v == p) {
			continue;
		}
		pref.push_back(dp[v]);
		suf.push_back(dp[v]);
	}
	suf.push_back(1);
	for (int i = 1; i < (int) pref.size(); i++) {
		pref[i] = (pref[i] * pref[i - 1]) % mod;
	}
	for (int i = (int) suf.size() - 2; i >= 0; i--) {
		suf[i] = (suf[i] * suf[i + 1]) % mod;
	}
	ans[u] = pref.back() * ways_now % mod;
	int i = 0;
	for (int v : adj[u]) {
		if (v == p) {
			continue;
		}
		ll next_ways = pref[i] * suf[i + 1] % mod;
		next_ways = next_ways * ways_now % mod;
		next_ways = (next_ways + 1) % mod;
		dfs_two(v, u, next_ways);
		i++;
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> N >> mod;
	int x, y;
	for (int i = 0; i < N - 1; i++) {
		cin >> x >> y;
		x--, y--;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	dfs_one(0, -1);
	dfs_two(0, -1, 1);
	for (int i = 0; i < N; i++) {
		cout << ans[i] << "\n";
	}
	
	return 0;
}


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
ll LCM(int a, int b){
    return a*b/gcd(a,b);
}

int main(void){
    ll x;
    cin>>x;
    rep(a,-118,119+1){
        rep(b,-119,118+1){
            ll num = a*a*a*a*a - b*b*b*b*b;
            if(num==x){
                cout<<a<<" "<<b<<endl;
                return 0;
            }
        }
    }

    return 0;

}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> a[100005];
int bit[100005];
void add(int x, int d) {
  for (; x <= 100000; x += (x & -x)) {
    bit[x] += d;
  }
}
int sum(int x) {
  if (x == 0) return 0;
  int s = 0;
  for (; x >= 1; x -= (x & -x)) {
    s += bit[x];
  }
  return s;
}
int main() {
  int n, m, l, r;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &l, &r);
    a[r - l + 1].push_back({l, r});
  }
  for (int i = 1; i <= m; i++) {
    int ans = n;
    for (int j = i; j <= m; j += i) {
      ans += sum(j);
    }
    for (auto p : a[i]) {
      add(p.first, 1);
      add(p.second + 1, -1);
      n--;
    }
    printf("%d\n", ans);
  }
  return 0;
}


Measured memory_bytes: 7936