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

const int mod = 1e9 + 7;

int dp[1 << 21], G[21][21];
int n;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cin >> G[i][j];
        }
    }
    dp[0] = 1;
    for(int S = 0; S < (1 << n); S++) {
        if(!dp[S]) continue;
        dp[S] %= mod;
        int cnt = __builtin_popcount(S);
        for(int i = 0; i < n; i++) {
            if(G[cnt][i] && !(S & (1 << i))) {
                dp[S ^ (1 << i)] += dp[S];
            }
        }
    }
    cout << dp[(1 << n) - 1] << '\n';
    return 0;
}


Measured memory_bytes: 20004
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
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;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	int n;
	cin >> n;
	long long int dp[120][10] = {};
	long long int value[120][11] = {};
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int a;
			cin >> a;
			dp[i][j] = a;
		}
	}
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 11; j++) {
			int a;
			cin >> a;
			value[i][j] = a;
		}
	}
	int numbers[10] = {};
	long long int ans = -1000000000000;
	for (int i = 0; i < 1023; i++) {
		long long int thissum = 0;
		numbers[0] = numbers[0] + 1;
		for (int j = 0; j < 10; j++) {
			if (numbers[j] == 2) {
				numbers[j] = 0;
				numbers[j+1] = numbers[j+1] + 1;
			}
		}

		for (int j = 0; j < n; j++) {
			int sum = 0;
			for (int k = 0; k < 10; k++) {
				if (dp[j][k] == 1 && numbers[k] == 1) {
					sum++;
				}
			}
			thissum = thissum + value[j][sum];
		}
		ans = max(ans, thissum);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e5 + 10;
ll dp[1 << 18];
int a[1 << 18];
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, c = 0;
    ll mx;
    cin >> n;
    mx = (1 << n);
    for (int i = 0; i < mx; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < mx; i++) dp[i] = mx*i;
    ll ans = 0;
    for(int s = 1; s < mx; s++) {
        for(int i = 0; i < n; i++) {
            if((s >> i) & 1) {
                int s0 = s ^ (1 << i);
                ll tmp[4] = {dp[s0]%mx, dp[s0]/mx, dp[s]/mx, dp[s]%mx};
                sort(tmp, tmp + 4, [&](ll x, ll y){return a[x]>a[y];});
                unique(tmp, tmp + 4);
                dp[s] = tmp[0]+tmp[1]*mx;
            }
        }
        ll res = a[dp[s]/mx] + a[dp[s]%mx];
        ans = max(ans, res);
        cout << ans << endl;
    }
    return 0;
}

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

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
//g++ -std=c++11 

using namespace std;

int main(){
	string S;
	cin >> S;
	long long ans = 0;
	rep(i, S.size()/2) {
		if(S[i] != S[S.size() - 1 - i]) {
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3528
// Winners don't quit and Quitters don't win
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 998244353
#define MAX 100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s,t;
    int i,c=0;
    cin>>s;
    cin>>t;
    for(i=0;i<=2;++i){
    	if(s[i]==t[i]){
    		c++;
		}
	}
	cout<<c;
}

Measured memory_bytes: 256
want = [0,0,0]
ans = []
N,want[0],want[1],want[2] = map(int,input().split())
L = []
for _ in range(N):
    L.append(int(input()))

table = [0,1,2,-1]
import itertools as it
c = list(it.product(table, repeat=N))
for x in c:
    A = 0
    B = 0
    C = 0
    cnt = -3
    z = list(zip(x,L))
    for y in z:
        if y[0] == 0:
            A += y[1]
            cnt += 1
        elif y[0] == 1:
            B += y[1]
            cnt += 1
        elif y[0] == 2:
            cnt += 1
            C += y[1]
        else:
            pass
    if A*B*C == 0:
        continue
    ans.append(abs(A-want[0])+abs(B-want[1])+abs(C-want[2])+cnt*10)
print(min(ans))

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

typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int t = (C + B - 1)/B;
    int a = (A + D - 1)/D;
    if (t<=a) cout << "Yes" << "\n";
    else cout << "No" << "\n";

    return 0;
}

Measured memory_bytes: 3612
#include<iostream>

using namespace std;


int SelectionSort(int*Array, const int Num) {
	int SortNum = 0;

	for (int i = 0; i < Num; i++) {
		int minj = i;
		int tmp = *(Array + i);

		for (int j = i; j < Num; j++) {
			if (*(Array + j) < *(Array + minj))minj = j;
		}

		if (i < minj) {
			*(Array + i) = *(Array + minj);
			*(Array + minj) = tmp;
			SortNum++;
		}
	}

	return SortNum;
}

int main() {
	int N;
	int Array[100];
	int SortNum;

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

	SortNum = SelectionSort(Array, N);

	cout << Array[0];
	for (int i = 1; i < N; i++)cout << " " << Array[i];
	cout << endl;
	cout << SortNum << endl;

	return 0;
}

Measured memory_bytes: 1164
import java.io.*;
import java.util.*;
import java.lang.*;

public class Main {
 public static void main (String[] args) {
  Scanner sc = new Scanner (System.in);
   int n = sc.nextInt();
   int x = sc.nextInt();
   
   System.out.println(n*500>=x ? "Yes" : "No");
 }
}

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

#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(box) box.begin(), box.end()

using namespace std;

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

const long long INF = LLONG_MAX/3;

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; }

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[a]+=siz[b];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

const int MOD=1e9+7;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		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;
    	}
		COMinited=true;
	}
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}
bool ischar(char c){
	if('A'<=c&&c<='Z')return true;
	else return false;
}
signed main(){
	string s,t;
	cin>>s>>t;
	int a,b;
	cin>>a>>b;
	string u;
	cin>>u;
	if(s==u)a--;
	else b--;
	cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 764
#include<stdio.h>
#include<math.h>
#define N 1000

int main(void){
  int i,num;
  int x[N],h[N];
  double sur;

  for(i=0;;i++){
    scanf("%d%d",&x[i],&h[i]);
    if(x[i]==0 && h[i]==0)
      break;
  }
  num=i;
  for(i=0;i<num;i++){
    sur=0.0;
    sur+=x[i]*x[i];
    sur+=(sqrt(h[i]*h[i]+x[i]*x[i]/4.0)*x[i])*2.0;
    printf("%0.6f\n",sur);
  }
  return 0;
}

Measured memory_bytes: 0
N = int(input())
A = input()
B = input()
C = input()
wordlst = [A, B, C]
cnt = 0
for i in range(N):
    tmp = 0
    for j in range(3):
        tmp += wordlst[j - 1][i].count(wordlst[j][i])
        tmp += wordlst[j - 2][i].count(wordlst[j][i])
    if tmp == 0:
        cnt += 2
    elif tmp == 2:
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
N = int(input())

Sum = (N * (N+1)) / 2

a = N // 3
b = N // 5
c = N // 15

A = a * (3 + 3*a) / 2
B = b * (5 + 5*b) / 2
C = (c * 15 * (c+1)) / 2

ans = int(Sum + C - (A+B))
print(ans)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REP(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define REP1(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Int = long long;
 
//INT_MAX = 2147483647;
//LLONG_MAX = 9223372036854775807;
//ULLONG_MAX = 18446744073709551615;
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;
 
//少数点表示
//cout << std::fixed << std::setprecision(14) << 値
 
int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    map<string, int> mp;
    mp["AC"]=0;
    mp["WA"]=0;
    mp["TLE"]=0;
    mp["RE"]=0;
    int n;
    cin >> n;
    rep(i,n){
        string s;
        cin >> s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;

    return 0;
}


Measured memory_bytes: 3672
import math
def dist(a,b):
  ret=0
  for (x,y)in zip(a,b):
    ret+=pow(x-y,2)
  return math.sqrt(ret)
point=[]
n,d=map(int,input().split())
for i in range(n):
  point.append(list(map(int,input().split())))
ans=0
for i in point:
  for j in point:
    if i==j:
      continue
    if dist(i,j)%1==0:
      ans+=1
print(int(ans/2))

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

int main (void) {
    int n, i;
    scanf("%d", &n);
    int a[n];
    int is_denied=0;
    for ( i=0; i<n; i++ ) {
        scanf("%d", &a[i]);
        if ( a[i]%2 == 0 ) {
            if ( a[i]%3 != 0 && a[i]%5 != 0 )
                is_denied = 1;
        }
    }

    if ( is_denied == 0 )
        printf("APPROVED\n");
    else
        printf("DENIED\n");

    return EXIT_SUCCESS;
}


Measured memory_bytes: 128
#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;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = ~(1<<31);
const int MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main(){
	int n;
	cin >> n;
	vi b(n),num(n,INF);
	for(int i = 0; i < n-1; i++) cin >> b[i];

	for(int i = 0; i < n-1; i++){
		num[i] = min(num[i],b[i]);
		num[i+1] = min(num[i+1],b[i]);
	}

	ll sum = 0;
	rep(i,n) sum += num[i];
	cout << sum << endl;

	return 0;
}

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

const int N = 1e5+5, INF = 1e9+9;
int n, a[N], dp[N];

int main()
{
  cin >> n;
  for (int i = 1; i <= n; i++)
  {
    cin >> a[i];
    dp[i] = INF;
  }
  dp[1] = 0;
  for (int i = 1; i <= n; i++)
  {
    for (int j = i+1; j <= min(i+2, n); j++)
    {
      dp[j] = min(dp[j], dp[i] + abs(a[i]-a[j]));
    }
  }
  cout << dp[n];
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define DEBUG(x) cout << #x << " is " << (x) << endl;
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <functional>
#include <queue>
#include <tuple>

using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using ll = long long;
using vll = vector<ll>;
using pii = pair<int, int>;
using vb = vector<char>;
using vvb = vector<vb>;

#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define mp(a, b) make_pair(a,b)

#define fi first
#define sn second
#define decpii(p) p.fi--,p.sn--;


#ifdef LOCAL
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define dumpn(c) cerr << "> " << #c << " = " << (c) << ", ";
#else
#define dump(c) ;
#define dumpn(c) ;
#endif


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, (int) a.size())os << (i ? " " : "") << a[i];
    return os << ']';
}


int dxf[] = {1, 0, -1, 0};
int dyf[] = {0, -1, 0, 1};

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

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

inline vi uni(vi &vec) {
    sort(vec.begin(), vec.end());
    vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll fpow(ll x, ll p) {
    ll ans = 1;
    while (p > 0) {
        if ((p & 1) == 1) {
            ans *= x;
        }
        x *= x;
        p >>= 1;
    }
    return ans;
}

struct ____ {
    ____() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} ________;

string solve() {
    string s;
    cin >> s;
    int K;
    cin >> K;
    int n = s.length();

    set<string> res;
    rep(i, n) {
        stringstream ss;
        REP(j, i, min(n, i + K + 1)) {
            ss << s[j];
            res.insert(ss.str());
        }
    }

    auto it = begin(res);
    K--;
    rep(i, K) {
        ++it;
    }
    return *it;
}

int main() {
    cout << solve() << endl;
    return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<long long> ans(N + 1);
    ans[0] = 2;
    ans[1] = 1;
    for (int i = 2; i <= N; i++)
    {
        ans[i] = ans[i - 2] + ans[i - 1];
    }
    cout << ans[N] << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#pragma endregion Macros

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

    string ans;
    for (int i = 0; i < s.size(); i++) {
        if(s[i] == 'B') {
            if(ans.size() != 0){
                ans.pop_back();
            }
        }else{
            ans.push_back(s[i]);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

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

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (a[a[i]] == i) {
            ans++;
        }
    }
    cout << ans / 2 << endl;
}


Measured memory_bytes: 640
N, X = gets.chop.split.map(&:to_i)
L = gets.chop.split.map(&:to_i)
sum = 0
ans = 0
L.each do |len|
  if sum <= X
    ans += 1
  end
  sum += len
end

if sum <= X
  ans += 1
end

print ans

Measured memory_bytes: 1788
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    r = int(n ** 0.5) + 1
    for i in range(r,0,-1):
        if n%i==0:
            print(i+n//i-2)
            break
main()


Measured memory_bytes: 3060
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: u32) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let nw: Vec<u32> = read_vec();
    let n = nw[0];
    let mut w = nw[1] as f64;

    let mut vw: Vec<Vec<f64>> = read_vec2(n);

    vw.sort_by(|a, b| (b[0] / b[1]).partial_cmp(&(a[0] / a[1])).unwrap());

    let mut ans: f64 = 0.0;

    for i in 0..(n as usize) {
        if w >= vw[i][1] {
            w -= vw[i][1];
            ans += vw[i][0];
        } else {
            ans += vw[i][0] / vw[i][1] * w;
            w = 0.0;
        }
    }

    println!("{}", ans);
}



Measured memory_bytes: 11064
def check(m, f, r)
  return 'F' if m == -1 || f == -1
  return m + f >= 80 ? 'A' : m + f >= 65 ? 'B' : m + f >= 50 || m + f >= 30 && r >= 50 ? 'C' : m + f >= 30 ? 'D' : 'F'
end

while (n = gets.split(' ').map(&:to_i)) != [-1, -1, -1]
  m, f, r = n
  puts check(m, f, r)
end

Measured memory_bytes: 8652
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;

namespace mp = boost::multiprecision;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 100005;

int N,M;

vector<int> Edge[MAX_N];
vector<int> rEdge[MAX_N];
int outEdge[MAX_N];
int dp[MAX_N];

signed main()
{
  cin >> N >> M;
  REP(m,M) {
    int a,b; cin >> a >> b; a--; b--;
    Edge[a].push_back(b); outEdge[a]++;
    rEdge[b].push_back(a);
  }

  queue<int> que;
  REP(n,N) {
    if(outEdge[n] == 0) {
      que.push(n);
    }
  }

  int ans = 0;
  while(que.size()) {
    int pos = que.front(); que.pop();
    for(int next : rEdge[pos]) {
      dp[next] = max(dp[next], dp[pos]+1);
      ans = max(ans, dp[next]);
      outEdge[next]--; if(outEdge[next] == 0) que.push(next);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 12800
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.*;
import java.util.Map.Entry;

public class Main{
	
	public static void main(String[] args) throws IOException{
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		Scanner in = new Scanner(System.in);
		
		int H = in.nextInt();
		int W = in.nextInt();
		int N = in.nextInt();
		String[][] sList = new String[H][W];
		int indexH = 0;
		int indexW = 0;
		
		for(int i = 0; i < N; i++){
			int a = in.nextInt();
			int c = i + 1;
			for(int j = 0; j < a; j++){
				sList[indexH][indexW] = "" + c;
				indexW++;
				if(indexW == W){
					indexH++;
					indexW = 0;
				}
			}
		}
		
		for(int i = 0; i < H; i++){
			if(i % 2 == 0){
				for(int j = 0; j < W - 1; j++){
					System.out.print(sList[i][j] + " ");
				}
				System.out.println(sList[i][W-1]);
			}
			else{
				for(int j = W - 1; j >= 1; j--){
					System.out.print(sList[i][j] + " ");
				}
				System.out.println(sList[i][0]);
			}
		}
	}
}


Measured memory_bytes: 36256
#include<stdio.h>
int main(void){
  int A;
  int B;
  int C;
  1<=A,B,C;
  A,B,C<=100;
  scanf("%d",&A);
  scanf("%d",&B);
  scanf("%d",&C);
  if((A==B)&&(B==C)&&(C==A)){
    printf("Yes");
  }else{
    printf("No");
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
ll MOD = 1000000007;
ll INF = 200000000000000000;
double EPS = 1e-12;
double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
  ll N,K;
  cin >> N >> K;
  cout << N - K + 1 << endl;
} 


Measured memory_bytes: 256
Imports System.Console
Module Module1
    Sub Main()
        Dim n As Integer = ReadLine()
        Dim ans As Integer
        If n >= 400 Then
            If n <= 599 Then
                ans = 8
            ElseIf n <= 799 Then
                ans = 7
            ElseIf n <= 999 Then
                ans = 6
            ElseIf n <= 1199 Then
                ans = 5
            ElseIf n <= 1399 Then
                ans = 4
            ElseIf n <= 1599 Then
                ans = 3
            ElseIf n <= 1799 Then
                ans = 2
            ElseIf n <= 1999 Then
                ans = 1
            End If
        End If
        WriteLine(ans)
    End Sub
End Module



Measured memory_bytes: 28352
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout << fixed << setprecision(10) << p;
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define mod 1000000007
#define PI 3.14159265358979323
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define debug(x) cout<<"Case "<<x<<": "
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

int main(int argc, char const *argv[])
{
	sync;
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif*/
	ll n;
	cin>>n;
	ld a[n+5]={0},dp[n+5][n+5]={0};
	f(i,1,n+1)cin>>a[i];
	f(i,0,n+1)
	{
		f(j,0,i+1)
		{
			if(i==0)
				dp[i][j]=1;
			else if(j==0)
				dp[i][j]=dp[i-1][j]*(1-a[i]);
			else if(j==i)
				dp[i][j]=dp[i-1][j-1]*a[i];
			else
				dp[i][j]=dp[i-1][j]*(1-a[i])+dp[i-1][j-1]*a[i];
		}
	}
	ld sum=0;
	f(j,n/2+1,n+1)sum+=dp[n][j];
	cout<<fixed<<setprecision(10)<<sum;

}


Measured memory_bytes: 141312
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n,c,k = lr()
t = [ir() for i in range(n)]
t.sort()
ans = 0
count = 0
ind = 0
while ind < n:
    now = t[ind]
    while ind < n and t[ind] <= now+k and count < c:
        ind+=1
        count+=1
    ans+=1
    count=0
print(ans)

Measured memory_bytes: 81276
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) {
            System.out.println("a < b");
        } else if (a > b) {
            System.out.println("a > b");
        } else if (a == b) {

            System.out.println("a == b");
        }
    }
}


Measured memory_bytes: 26424
n,m,q=map(int,input().split())

#G[i][j]=(i,j)なる列車の本数
G=[[0]*(n+1) for i in range(n+1)]
for i in range(m):
    l,r=map(int,input().split())
    G[l][r]+=1



#S[i][j]=(i以下,j以下)なる列車の本数(i<=j)
S=[[0]*(n+1) for i in range(n+1)]
for i in range(1,n+1):
    for j in range(1,n+1):
        S[i][j]=S[i-1][j]+S[i][j-1]-S[i-1][j-1]+G[i][j]





for i in range(q):
    s,f=map(int,input().split())
    print(S[f][f]-S[s-1][f]-S[f][s-1]+S[s-1][s-1])



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

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/

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

int main(){
    int n;scanf("%d",&n);
    printf("0\n");fflush(stdout);
    int l=0,r=n;
    int lp,rp;
    char s[15];
    scanf("%s",s);
    if(s[0]=='V')return 0;
    if(s[0]=='M')lp=rp=1;
    else lp=rp=2;
    
    while(1){
        int m=(l+r)/2;
        printf("%d\n",m);
        fflush(stdout);
        scanf("%s",s);
        if(s[0]=='V')return 0;
        int mp;
        if(s[0]=='M')mp=1;
        else mp=2;
        int a=0;
        if(lp==mp)a++;
        if((m-l)%2==0)a++;
        if(a==1){
            r=m;
            rp=mp;
        }else{
            l=m;
            lp=mp;
        }
    }
    return 0;
}


Measured memory_bytes: 852
n = int(input())
A = [*map(int, input().split())]
def solve():
    MAX_A = 10**6 + 1
    C = [0] * MAX_A
    for a in A: C[a] += 1
    pairwise = True
    if sum(C[2::2]) > 1: pairwise = False
    for i in range(3, MAX_A, 2):
        if sum(C[i::i]) > 1: pairwise = False
    if pairwise: return 'pairwise'
    from math import gcd
    g = 0
    for a in A: g = gcd(g, a)
    if g == 1: return 'setwise'
    return 'not'
print(solve(), 'coprime')


Measured memory_bytes: 126712
#include <stdio.h>

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

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

  long long sum = 0;
  for (int i = N-1; i >= 0; i--) {
    if((A[i]+sum)%B[i] != 0) sum += B[i]-(A[i]+sum)%B[i];
  }

  printf("%lld\n", sum);

  return 0;
}

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

int main() {
	string S;
	cin >> S;
	int ans = 700;
	for (int i = 0;i < 3;i ++) ans += S[i] == 'o' ? 100 : 0;
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

単にoの数*100を足すだけね
*/

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	static class City implements Comparable<City> {

		public int getP() {
			return P;
		}

		public void setP(int p) {
			P = p;
		}

		public int getY() {
			return Y;
		}

		public void setY(int y) {
			Y = y;
		}

		public int getSORT() {
			return SORT;
		}

		public void setSORT(int sORT) {
			SORT = sORT;
		}

		public String getCityNumber() {
			return cityNumber;
		}

		public void setCityNumber(String cityNumber) {
			this.cityNumber = cityNumber;
		}

		int P;
		int Y;
		int SORT;
		String cityNumber;

		public City() {
		}

		@Override
		public int compareTo(City o) {
			// TODO Auto-generated method stub
			int i = this.P - o.P;
			if (i == 0) {
				return this.Y - o.Y;
			}
			return i;
		}
	}

	public static void main(String args[]) throws Exception {

		int N;
		int M;
		int P;
		int Y;

		ArrayList<City> citys = new ArrayList<>();
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();

		if (N >= 1 && N <= (int)Math.pow(10,5)) {
			M = sc.nextInt();
			sc.nextLine();
			if (M >= 1 && M <= (int)Math.pow(10,5)) {
				for (int i = 1; i <= M; i++) {
					P = sc.nextInt();
					if (P >= 1 && P <= N) {
						Y = sc.nextInt();
						if (Y >= 1 && Y <= (int)Math.pow(10,9)) {
							City city = new City();
							city.setCityNumber("");
							city.setP(P);
							city.setSORT(i);
							city.setY(Y);
							sc.nextLine();
							citys.add(city);
						}

					}

				}

			}
		}
		Collections.sort(citys);
		int i = 0;
		int currentP = 1;
		for (City city : citys) {
			String cityName = "";
			int tempP1 = city.P;
			if (tempP1 == currentP) {
				i++;
			} else {
				i = 1;
				currentP = tempP1;
			}
			currentP = tempP1;
			String city1 = addZeroForNum(String.valueOf(city.P), 6);
			String city2 = addZeroForNum(String.valueOf(i), 6);
			String cityTemp = city1 + city2;
			city.setCityNumber(cityTemp);
		}
		Collections.sort(citys, new Comparator<City>() {

			@Override
			public int compare(City o1, City o2) {
				return o1.SORT - o2.SORT;
			}
		});
		for (City city : citys) {
			System.out.println(city.getCityNumber());
		}

	}

	public static String addZeroForNum(String str, int strLength) {
		int strLen = str.length();
		StringBuffer sb = null;
		while (strLen < strLength) {
			sb = new StringBuffer();
			sb.append("0").append(str);// 左补0
			// sb.append(str).append("0");//右补0
			str = sb.toString();
			strLen = str.length();
		}
		return str;
	}

}


Measured memory_bytes: 166076
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
//string binary = bitset<32>(n).to_string();
int main()
{
 	ios::sync_with_stdio(0);
    cin.tie(0);
  lli n,m;
	cin>>n>>m;
	lli temp[100002]={0};
	for(lli i=0;i<m;i++){
		lli a,b;
		cin>>a>>b;
		temp[a]++;temp[b+1]--;
	}
	for(lli i=1;i<=n;i++)temp[i]=temp[i-1]+temp[i];
		lli ct=0;
	for(lli i=0;i<=n;i++)if((temp[i]/m)!=0)ct++;
	//for(lli i=0;i<=n;i++)cout<<temp[i]<<" ";
    cout<<ct;
    return 0;
}


Measured memory_bytes: 1024
s=list(input())
s=s+["R"]
n=len(s)-1
ans_list=[0 for i in range(n)]

flg_1=0
flg_2=0
start=0
for i in range(1,n+1):
  if s[i-1]=="R" and s[i]=="L":
    flg_1=i
  elif s[i-1]=="L" and s[i]=="R":
    flg_2=i
    if (flg_2-start)%2==0:
      if (flg_1-start)%2!=0:
        ans_list[flg_1-1]=(flg_2-start)//2
        ans_list[flg_1]=(flg_2-start)//2
      else:
        ans_list[flg_1-1]=(flg_2-start)//2
        ans_list[flg_1]=(flg_2-start)//2
    else:
      if (flg_1-start)%2!=0:
        ans_list[flg_1-1]=(flg_2-start)//2+1
        ans_list[flg_1]=(flg_2-start)//2
      else:
        ans_list[flg_1-1]=(flg_2-start)//2
        ans_list[flg_1]=(flg_2-start)//2+1
    start=i

for i in ans_list:
  print(str(i)+str(" "),end="")
        
    

Measured memory_bytes: 10532
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

#define Max 210000

ll X[Max];
ll Xs[Max];
int N;

int main(int argc, const char * argv[]) {
    N = inputValue();
    inputArray(X, N);
    rep(i, N) {
        Xs[i] = X[i];
    }

    sort(Xs, Xs+N);
    int base = N/2-1;
    repd(i, 0, N) {
        int ofs = 0;
        if (X[i] == Xs[base]) {
            ofs = 1;
        }
        else if (X[i] > Xs[base]) {
            ofs = 0;
        }
        else if (X[i] < Xs[base]) {
            ofs = 1;
        }
        output(Xs[base+ofs]);
    }

    return 0;
}

Measured memory_bytes: 5376
num = int(input())
arr = input().split()
count = 0
 
for i in range(1, num-1):
  if int(arr[i-1]) < int(arr[i]) < int(arr[i+1]) or int(arr[i-1]) > int(arr[i]) > int(arr[i+1]): count +=1
    
print(count)

Measured memory_bytes: 9128
#include<iostream>
#include<cstdio> 
#include<algorithm>
using namespace std;
int n,m,i,j,k,a[200010],b;
long long ans;
int absx(int x){
	if (x>=0) return x; else return -x;
}
int main(){
	scanf("%d",&n);for (i=1;i<=n;i++) scanf("%d",&a[i]);for (i=1;i<=n;i++) a[i]-=i;
	sort(a+1,a+n+1);if (n%2==1) b=a[n/2+1]; else b=(a[n/2]+a[n/2+1])/2;
	for (i=1;i<=n;i++) ans+=absx(b-a[i]);printf("%lld\n",ans);return 0;
}

Measured memory_bytes: 1024
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e9) + 1;
const int mod = 479001599;
const int maxn = 5e5 + 111;
        
using namespace std;          

int n, m, k, dp[2000][2000], ans;

int get(int x2, int y2, int x1, int y1){
	int x = dp[x2][y2] - dp[x2][y1] - dp[x1][y2] + dp[x1][y1];
	//cout << x1 << " " << y1 << " " << x2 << " " << y2 << " -> " << x << endl;
	return x;
}

void solve(){
	cin >> n >> m >> k;

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++){
			char x;
			cin >> x;
			dp[i][j] = x - '0';
			//if (x == '0')
				//cout << i << " " << j << endl;
		}

	ans = n + m - 2;

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			dp[i][j] += dp[i][j - 1];
   	
   	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			dp[i][j] += dp[i - 1][j];

   	/*for (int i = 1; i <= n; i++){
   		for (int j = 1; j <= m; j++)
   			cout << dp[i][j] << " ";
   		cout << endl;
   	}*/  

	for (int mask = 0; mask < (1 << (n - 1)); mask++){
		//cout << mask << " ";
		vector <int> v;
		v.pb(0);
		for (int j = 0; j < n - 1; j++)
			if ((mask & (1 << j)) > 0)
				v.pb(j + 1);
		v.pb(n);
		int mx = sz(v) - 2;
		int pos = 0;
		for (int j = 1; j <= m; j++){
			for (int i = 0; i < sz(v) - 1; i++){
				int x = get(v[i + 1], j, v[i], pos);
				if (j - pos == 1 && x > k){
					mx = inf;
					break;
				}
				if (x > k){
					mx++;
					pos = j - 1;
					break;
				}
			}
		}
		//cout << ans << " " << mx << " " << mask << endl;
		ans = min(ans, mx);
	}

	cout << ans;
}                              
      
main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

    boost;
    
    int q = 1;
 
    //cin >> q;
    
    while (q--){
        solve();
    }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int x=a[n-1];
	for(int i=n-1;i>=0;i--){
		if(a[i]<=x){
			x=a[i];
		}
		else {
			if(a[i]-1<=x){
				x=a[i]-1;
			}
			else{
				cout<<"No";
				return 0;
			}
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007;

int n,a[50];

int solve (int i, int m){
  if(m == 0) return 1;
  if(i >= n) return 0;
  return solve(i+1, m) || solve(i+1, m-a[i]);
}

int main(){
  int q,m;
  cin >> n;
  rep(i,n) cin >> a[i];
  cin >> q;
  rep(i,q){
    cin >> m;
    if( solve(0, m) ) cout << "yes\n";
    else cout << "no\n";
  }
}


Measured memory_bytes: 3100
#include<stdio.h>

int main(){
	int i;
	int n;
	int j;
	int l;
	int m;
	int c = 0;
	while(scanf("%d", &n) != EOF){
		for(i = 0; i < 10; i++){
			for(j = 0; j < 10; j++){
				for(l = 0; l < 10; l++){
					for(m = 0; m < 10; m++){
						if(n == i + j + l + m){
							c++;
						}
					}
				}
			}
			
		}
	
	printf("%d\n", c);
	c = 0;
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=201000;
int n,a[N];
int nxt[N],pos[N],dp[N];
int main() {
	scanf("%d",&n);
	rep(i,1,n+1) scanf("%d",a+i);
	rep(i,1,n+1) nxt[i]=pos[a[i]],pos[a[i]]=i;
	dp[0]=1;
	rep(i,1,n+1) {
		dp[i]=dp[i-1];
		if (nxt[i]!=i-1&&nxt[i]!=0) dp[i]=(dp[i]+dp[nxt[i]])%mod;
	}
	printf("%d\n",dp[n]);
}

Measured memory_bytes: 3456
#include<stdio.h>

int ans;

void swap_(int *f, int *b) {
int temp;
temp = *f;
*f = *b;
*b = temp;
ans++;
}

void bSort(int arr[], int n) {

    for(int i = 0; i < n-1; i++) {
        for(int j = 0; j < n-i-1; j++) {
		if ( arr[j] > arr[j+1])
	     swap_(&arr[j], &arr[j+1]);
        }
    }
    return;
}


int main() {

    int n;
    int arr[100+5];
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%d", &arr[i]);
    bSort(arr, n);
    for(int i = 0; i < n ; i++) {
        if( i > 0 ) printf(" ");
        printf("%d", arr[i]);
    }
    printf("\n%d\n", ans);
    return 0;
}



Measured memory_bytes: 2756
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=10000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
int n;
double dp[3030][3030];

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
	n=read();dp[0][0]=1;
	rep(i,1,n)
	{
		double p;
		scanf("%lf",&p);
		rep(j,0,i)
		{
			if (j) dp[i][j]=dp[i-1][j-1]*p;
			dp[i][j]+=dp[i-1][j]*(1.0-p);
		}
	}
	double ans=0;
	rep(i,(n+1)/2,n) ans+=dp[n][i];
	printf("%0.12lf",ans);
	return 0;
}


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

int main(){
    //input
    long long N,A,B;
    cin >> N >> A >> B;
    //calculate
    long long answer;
    if(A>B)
        answer = 0;
    else if(N==1)
        answer = (A==B ? 1 : 0);
    else
        answer = (B-A)*(N-2)+1;
    //output
    cout << answer << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
int main(){
 int n ,k ;
  cin >> n >> k ;
    int a[n] ;
  for(int i = 0 ; i < n ;  i ++ ){
    cin >> a[i] ;
  }
  sort(a, a + n);
  long long sum = 0 ;
  cout << accumulate(a , a + k , sum) ;
}


Measured memory_bytes: 3644
#define DEBUG 0

/**
 * File    : B.cpp
 * Author  : Kazune Takahashi
 * Created : 6/9/2019, 9:02:13 PM
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <random>
#include <chrono>
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

/*
void Yes()
{
  cout << "Yes" << endl;
  exit(0);
}

void No()
{
  cout << "No" << endl;
  exit(0);
}
*/

/*
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
*/

// const ll MOD = 1000000007;

int N;
ll W[110];

int main()
{
  cin >> N;
  for (auto i = 0; i < N; i++)
  {
    cin >> W[i];
  }
  ll ans = 10000000000000;
  for (auto i = 0; i <= N; i++)
  {
    ll A = 0, B = 0;
    for (auto j = 0; j < i; j++)
    {
      A += W[j];
    }
    for (auto j = i; j < N; j++)
    {
      B += W[j];
    }
    ans = min(ans, abs(A - B));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256