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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};
typedef string S;
typedef vector<S> Vs;
typedef vector<int> V;
int R, C;
Vs in;
template <typename ITR>
bool next_value(int base, ITR bg, ITR ed) {
	int c = 1;
	for (; bg != ed && c == 1; ++bg) {
		(*bg) += c;
		if ((c = ((*bg) == base)))(*bg) = 0;
	}
	return !c;
}
int ans;
bool is_kaibun(string s) {
	auto t = s;
	reverse(ALL(t));
	return (s == t);
}
void solve(V order) {
	int ok = 1;
	map<string, int> kaibun, hutuu;
	auto t = in;
	for (int i : range(R)) {
		t[i] = in[order[i]];
	}
	for (int i : range(C)) {
		string x="";
		for (int j : range(R))x += t[j][i];
		if (is_kaibun(x))kaibun[x]++;
		else hutuu[x]++;
	}
	int odd = 0;
	for (auto &it : kaibun) {
		if(it.second%2==1) odd++;
	}
	for (auto &it : hutuu) {
		auto inv = it.first;
		reverse(ALL(inv));
		if (hutuu.count(inv) == 0 || hutuu[inv] != it.second)
			ok = 0;
	}
	if (odd > 1)ok = 0;
	if (odd == 1 && C % 2 == 0)ok = 0;
	ans |= ok;
}
const string ret[2] = { "NO","YES" };
void dfs(bitset<16> b, V order) {
	if (b.count() == 0) {
		V fixed = order;
		int i = 0, j = R - 1;
		int id = 0;
		if (R % 2 == 1) {
			fixed[R / 2] = order[id++];
		}
		while (i < j) {
			fixed[i] = order[id++];
			fixed[j] = order[id++];
			i++, j--;
		}
		solve(fixed);
	}
	else{
		for (int i : range(R)) {
			if (b[i]) {
				order.push_back(i);
				b[i].flip();
				break;
			}
		}
		for (int i : range(R)) {
			if (b[i]) {
				order.push_back(i);
				b[i].flip();
				dfs(b, order);
				order.pop_back();
				b[i].flip();
			}
		}
	}
}
int main() {
	while (cin >> R >> C) {
		ans = 0;
		in = Vs(R, S(C, '-'));
		cin >> in;
		if (R % 2 == 1) {
			for (int i : range(R)) {
				vector<int> a = { i };
				dfs(bitset<16>((1 << R) - 1 - (1<<i)), a);
			}
		}
		else {
			vector<int> a;
			dfs(bitset<16>((1 << R) - 1), a);
		}
		cout << ret[ans] << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import numpy as np

N, W = map(int, input().split())
WV = np.array([input().split() for _ in range(N)], np.int64)
V = sum(WV[:, 1])
INF = 1 << 60
dp = np.full(V + 1, INF)
dp[0] = 0
for w, v in WV:
    np.minimum(dp[v:], dp[:-v] + w, out=dp[v:])
for v in range(V + 1):
    if dp[v] <= W:
        ans = v
print(ans)


Measured memory_bytes: 21416
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        
        int ans = 0;
        for(int i=A; i<=B; i++){
            String[] s = Integer.toString(i).split("");
            if(s[0].equals(s[1]) && s[0].equals(s[3]) && s[0].equals(s[4]) &&
               s[1].equals(s[3]) && s[1].equals(s[4]) &&
               s[3].equals(s[4])){
                ans++;
            }else if(s[0].equals(s[4]) && s[1].equals(s[3])){
                ans++;
            }
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 62716
#include <bits/stdc++.h>
#include <iostream>
#define ll long long
using namespace std;
int main() {
	ll int n,temp,k,m;
	cin>>n>>k;
	vector<int> a(n);
	for(ll int i=0;i<n;i++){
		cin>>a[i];
		//a.push_back(temp);
	}
	ll int dp[n];
	dp[0]=0;
	dp[1]=abs(a[0]-a[1]);
	for(ll int i=2;i<a.size();i++){
		m=INT_MAX;
		for(ll int j=1;j<=min(i,k);j++){
			m=min(m,dp[i-j]+abs(a[i]-a[i-j]));
		}
		dp[i]=m;
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define rep(X,A,B) for(int X=A;X<=B;++X)
#define tep(X,A,B) for(int X=A;X>=B;--X)
#define LL long long
const int N=200010;
using namespace std;

LL M;
int n,maxn;
int a[N],b[N];
LL num[N<<1];

void READ(){
	scanf("%d",&n);
	rep(i,1,n)scanf("%d",&a[i]),b[i]=a[i];
	M=1LL*(n+1)*n/2;
	maxn=n<<1;
	maxn++;
}

int lowbit(int x){
	return x&(-x);
}

void ADD(int x,LL val){
	while(x<=maxn){
		num[x]+=val;
		x+=lowbit(x);
	}
}

LL QUE(int x){
	if(x<0)return 0;
	LL res=num[0];
	while(x>0){
		res+=num[x];
		x-=lowbit(x);
	}
	return res;
}

LL GET(int x){
	rep(i,0,maxn)num[i]=0;
	ADD(n+1,1);
	int now=0;
	LL res=0;
	rep(i,1,n){
		if(a[i]<=x)now++;else now--;
		res+=1LL*QUE(now+n);
		ADD(now+n+1,1);
	}
	return res;
}

void SOLVE(){
	sort(b+1,b+n+1);
	int l=1,r=n,res=1;
	while(l<=r){
		int mid=(l+r)>>1;
		if(GET(b[mid])<=M/2)l=mid+1;
		else r=mid-1,res=mid;
	}
	printf("%d\n",b[res]);
}

int main(){
	READ();
	SOLVE();
	return 0;
}

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

int main()
{
    string N;
    int len, sum;
    cin >> N;
    len = N.length();
    for (int i = 0; i < len; i++)
    {
        sum += N[i] - '0';
    }
    if (sum % 9 == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

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

int main() {
  int n;
  string s,t;
  cin >> n >> s >> t;
  int ans = 2*n;
  rep(i,1,n+1){
    if(s.substr(n-i,i) == t.substr(0,i)) ans = 2*n-i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N,X;
	cin>>N>>X;
	vector<int> L(N);
	rep(i,N)cin>>L[i];
	int now = 0;
	int ans = 1;
	rep(i,N){
		now += L[i];
		if(now <= X)ans++;
	}	
	cout<<ans<<endl;
}

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

#define pb(s) push_back(s)
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PI 3.14159265358979323846264338327950L


typedef long long ll;


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

    int N;
    string str;
    cin>>N>>str;
    int x=0;
    int ans=0;
    for(int i=0;i<str.size();++i){
        if(str[i]=='I'){
            x+=1;
            ans=max(ans,x);
        }
        else{
            x-=1;
        }
    }
    cout<<ans;
    return 0;
}


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

int main() {
    string s;
    cin >> s;
    int ans = 0;
    int len = s.length();

    for (int i = 0; i < len; ++i) {
        ans += (int)(s.front() - '0');
        s.erase(0, 1);

    }
    if (ans % 9 == 0) cout << "Yes" << '\n';
    else cout << "No" << '\n';

    return 0;
}


Measured memory_bytes: 3680
H, W = map(int, input().split())
S = [input() for _ in range(H)]
ans = "Yes"
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            p = n = f = b = False
            if i > 0:
                if S[i - 1][j] == "#":
                    p = True
            if H - 1 > i:
                if S[i + 1][j] == "#":
                    n = True
            if j > 0:
                if S[i][j - 1] == "#":
                    b = True
            if W - 1 > j:
                if S[i][j + 1] == "#":
                    f = True
            if (p or n or f or b) == False:
                ans = "No"
print(ans)

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

constexpr int inf = 0x3f3f3f3f;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int w, h;
  while (cin >> w >> h, w) {
    auto $ = [&](int i, int j) {
      return i * w + j;
    };
    vector<set<int>> g(h * w);
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        if (i + 1 < h) {
          g[$(i, j)].insert($(i + 1, j));
          g[$(i + 1, j)].insert($(i, j));
        }
        if (j + 1 < w) {
          g[$(i, j)].insert($(i, j + 1));
          g[$(i, j + 1)].insert($(i, j));
        }
      }
    }
    for (int i = 0; i < 2 * h - 1; ++i) {
      if (i % 2 == 0) {
        for (int j = 0; j < w - 1; ++j) {
          int x;
          cin >> x;
          if (x) {
            g[$(i / 2, j)].erase($(i / 2, j + 1));
            g[$(i / 2, j + 1)].erase($(i / 2, j));
          }
        }
      } else {
        for (int j = 0; j < w; ++j) {
          int x;
          cin >> x;
          if (x) {
            g[$(i / 2, j)].erase($(i / 2 + 1, j));
            g[$(i / 2 + 1, j)].erase($(i / 2, j));
          }
        }
      }
    }
    vector<int> d(h * w, inf);
    queue<int> que;
    d[$(0, 0)] = 0;
    que.push($(0, 0));
    while (not que.empty()) {
      int v = que.front();
      que.pop();
      for (int u : g[v]) {
        if (d[u] == inf) {
          d[u] = d[v] + 1;
          que.push(u);
        }
      }
    }
    int res = d[$(h - 1, w - 1)];
    cout << (res < inf ? res + 1 : 0) << '\n';
  }
}



Measured memory_bytes: 3352
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	int cnt=0;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		if(x>=k)
			cnt++;
	}
	cout<<cnt<<endl;
	
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}






Measured memory_bytes: 3640
#include <stdio.h>
#include <string.h>
int main(){
	char str[10001];
	char *p;
	int len;
	int cj,ci;
	while(1){
		if(scanf("%[^\n]\n",str)==EOF)break;
		len=strlen(str);
		cj=0;
		ci=0;
		if(len>=3){
			p=str+len-3;	//@-------***'\0'
			while(p>=str){
				if(!strcmp(p,"JOI"))cj++;
				if(!strcmp(p,"IOI"))ci++;
				*(p+2)='\0';
				if(p==str)break;
				if(p>str)p--;
			}
		}
		printf("%d\n%d\n",cj,ci);
	}
	return 0;
}

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

#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e6 + 6;
int dp[N][2];
string str;

int solve(int idx , int flag){
    if(idx == SZ(str)){
        if(flag)return 1e9;
        return 0;
    }

    int &ret = dp[idx][flag];
    if(~ret)return ret;
    ret = 1e9;
    if(flag){
        ret = min(ret , solve(idx + 1 , flag) + 9 - str[idx]);
        ret = min(ret , solve(idx + 1 , false) + 10 - str[idx]);
    }else{
        ret = min(ret , solve(idx , 1) + 1);
        ret = min(ret , solve(idx + 1 , false) + str[idx]);
    }
    return ret;
}

int main()
{

#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
	//freopen("out.in", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin >> str;
    for(char &c : str)c -= '0';
    memset(dp,-1,sizeof dp);
    cout << solve(0,0) << endl;

    return 0;
}


Measured memory_bytes: 56092
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 _main()
{
    int A, B;
    char op;
    cin >> A >> op >> B;
    cout << (op == '+' ? A + B : A - B) << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)




int main() {
    ll n;
    cin >> n;
    
    vector<ll> k;
    k.push_back(1);
    ll t1 = 6, t2 = 9;
    REP(i, 9){
        k.push_back(t1);
        k.push_back(t2);
        t1 *= 6;
        t2 *= 9;
    }
    
    sort(k.begin(), k.end());
    
    vector<ll> dp(n + 5, INF);
    
    dp[0] = 0;
    REP(i, k.size()){
        REP(j, n - k[i] + 1){
            dp[j + k[i]] = min(dp[j + k[i]], dp[j] + 1);
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 1024
n, m = map(int,input().split())
x = sorted(list( map(int,input().split())))
if n >= m:
    print(0)
else:
    d = [0]*(m-1)
    for i in range(m-1):
        d[i] = x[i+1] - x[i]
    d.sort()
    print(sum(d[0:m-n]))

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

int sort( const void * a , const void * b ) {
  return strcmp(( char * )a , ( char * )b );
}

int main(void){

  int N,i,ans = 1;
  char S[200001][11];
  size_t data_cnt;

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

  qsort(S,N,sizeof(S[0]),sort);

  for(i = 1;i < N;i++){
    if(strcmp(S[i-1],S[i])) ans++;
  }

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


Measured memory_bytes: 5736
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

map< int64_t, int > prime_factor(int64_t n) {
	map< int64_t, int > ret;
	for (int64_t i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

int main() {
	LL a, b; cin >> a >> b;

	auto primes = prime_factor(a);

	LL cnt = 1;
	for (auto p : primes) {
		if (b%p.first == 0) {
			cnt++;
		}
	}

	cout <<cnt<< endl;

	return 0;
}

Measured memory_bytes: 256
n = 2019
L,R =map(int,input().split())
l = L%n
N =min(2019,R-L+1)
ans = 2019
for i in range(N):
    for j in range(i):
        foo = (i+l)*(j+l)%n
        if ans > foo:
            ans = foo
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

/* modつき二分累乗法 */
ll modpow(ll a, ll b) {
    ll res = 1;
    for (a = a; b; a = a * a , b >>= 1){
        if (b & 1) res = res * a;
    }
    return res;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N,M,X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N,vector<int>(M));
    REP(i,N){
        cin >> C[i];
        REP(l,M){
            cin >> A[i][l];
        }
    }
    ll best = INT32_MAX;
    REP(i,modpow(2,N)){
        vector<int> where(N);
        int tmp = i;
        REP(l,N){
            if(tmp%2 == 1)where[l] = 1;
            tmp/=2;
        }
        vector<int> rikai(N);
        ll sum = 0;
        REP(l,N){
            if(where[l] == 1){
                sum += C[l];
                REP(a,M){
                    rikai[a] += A[l][a];
                }
            }
        }
        bool ok = 1;
        REP(l,M){
            if(rikai[l]<X)ok = 0;
        }
        if(ok)chmin(best,sum);
    }
    if(best == INT32_MAX)best = -1;
    cout << best << "\n";
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
using namespace std;
char s[1010101];
char t[1010101];
stack <int> p[26];
int q[1010101],qs=1,qe=0;
int cc[1010101];
int main()
{
	int n,la,now,c=0,ans=0;
	scanf("%d",&n);
	now=n;
	la=n+1;
	scanf("%s",s+1);
	scanf("%s",t+1);
	for(int i=1;i<=n;i++)
		p[s[i]-'a'].push(i);
	for(int i=n;i>=1;i--)
	{
		while(now>i)
			now--;
		while(!p[t[i]-'a'].empty()&&p[t[i]-'a'].top()>now)
			p[t[i]-'a'].pop();
		if(p[t[i]-'a'].empty())
		{
			printf("-1");
			return 0;
		}
		now=p[t[i]-'a'].top();
		if(now==la||now==i)
		{
			la=now;
			continue;
		}
		la=now;
		while(qs<=qe&&q[qs]-cc[qs]-c+1>i)
		{
			ans=max(ans,cc[qs]+c);
			qs++;
		}
		c++;
		q[++qe]=now;
		cc[qe]=1-c;
	}
	for(int i=qs;i<=qe;i++)
		ans=max(ans,cc[i]+c);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 14044
package main

import (
	"container/list"
	"fmt"
)

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	s := make([]string, h)
	ans := 0
	for i := range s {
		fmt.Scan(&s[i])
		for _, r := range s[i] {
			if r == '.' {
				ans++
			}
		}
	}

	type point struct{ x, y, d int }
	ps := list.New()
	ps.PushBack(point{0, 0, 1})
	passed := make([][]bool, h)
	for i := range passed {
		passed[i] = make([]bool, w)
	}
	for {
		p := ps.Remove(ps.Front()).(point)
		if p.x == h-1 && p.y == w-1 {
			ans -= p.d
			break
		}

		if p.x+1 < h && s[p.x+1][p.y] == '.' && !passed[p.x+1][p.y] {
			ps.PushBack(point{p.x + 1, p.y, p.d + 1})
			passed[p.x+1][p.y] = true
		}
		if p.y+1 < w && s[p.x][p.y+1] == '.' && !passed[p.x][p.y+1] {
			ps.PushBack(point{p.x, p.y + 1, p.d + 1})
			passed[p.x][p.y+1] = true
		}
		if p.x-1 >= 0 && s[p.x-1][p.y] == '.' && !passed[p.x-1][p.y] {
			ps.PushBack(point{p.x - 1, p.y, p.d + 1})
			passed[p.x-1][p.y] = true
		}
		if p.y-1 >= 0 && s[p.x][p.y-1] == '.' && !passed[p.x][p.y-1] {
			ps.PushBack(point{p.x, p.y - 1, p.d + 1})
			passed[p.x][p.y-1] = true
		}

		if ps.Len() == 0 {
			fmt.Println(-1)
			return
		}
	}
	fmt.Println(ans)
}


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

int main(void) {
  int n;
  cin >> n;
  ll a[n];
  rep(i,n) cin >> a[i];

  //2の倍数は2人で2個分
  //4の倍数は1人で3人分
  int cnt_4 = 0, cnt_2 = 0;
  rep(i,n){
    if(a[i] % 4==0) cnt_4++;
    if(a[i] % 2==0 && a[i] % 4 != 0) cnt_2++;
  }
  n -= cnt_4*2;
  n -= cnt_2/2*2;
  n -= 1;
  if(n > 0) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 4304
#include <stdio.h>
int main(void)
{
    int A;
    int B;
    int N;
    scanf("%d",&N);
    scanf("%d",&A);
    scanf("%d",&B);
    
    if(N*A<B)
    {
        printf("%d\n",N*A);
    }
    else
    {
        printf("%d\n",B);
    }
    return 0;   
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(n) for(int i=0;i<n;i++)
#define reps(i,s,n) for(int i=s;i<n;i++)
#define rep_bit(n) for (int bit = 0; bit < (1<<n); ++bit)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ll long long
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
using namespace std;
typedef vector<vector<int> > Graph;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;



int main(){

    ll a,b,c;
    cin >> a >> b >> c;

    if(c-a-b>0 && 4*a*b < (c-a-b)*(c-a-b)) CYES;
    else CNO;

    return 0;
}


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

bool is_prime(int n) {
  if (n == 2) return true;
  if (n % 2 == 0) return false;

  double sqrt_n = sqrt(n);
  for (int i = 3; i <= sqrt_n; i++)
    if (n % i == 0) return false;

  return true;
}

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

  int count = 0;

  for (int i = 0; i < n; i++) {
    cin >> m;
    if (is_prime(m)) count++;
  }

  cout << count << endl;

  return 0;
}



Measured memory_bytes: 3084
print(100000)
cnt = 100000

# Element 10000 is 1 if A + B > 0

print("+ 0 1 199999")
print("< 10000 199999 10000")

print("+ 0 10000 0")
print("+ 1 10000 1")

# From 100 ~ 129 we store 2^0 ~ 2^29

print("< 100 10000 100")
for i in range(29):
    print("+ " + str(100 + i) + " " + str(100 + i) + " " + str(100 + i + 1))

cnt -= 34

# From 150 to 179 we store binary representation of B, 1000 to 1029 we store 2^m * binary representation
for i in range(29,-1,-1):
    print("< " + str(100 + i) + " 1 " + str(150 + i))
    cnt -= 1
    print("+ " + str(150 + i) + " " + str(100000) + " " + str(1000 + i))
    cnt -= 1
    for j in range(i):
        print("+ " + str(1000 + i) + " " + str(1000 + i) + " " + str(1000 + i))
        cnt -= 1
    for j in range(i):
        print("+ " + str(100 + j) + " " + str(1000 + i) + " " + str(100 + j))
        cnt -= 1



# From 300 to 329 we store A if 150 + n is 1 else 0
for n in range(30):
    # From 100 ~ 129 we store 2^0 ~ 2^29
    for i in range(30):
        print("< " + str(100 + i) + " " + str(100 + i) + " " + str(100 + i))
        cnt -= 1
    print("< 100 199999 100")
    cnt -= 1
    for i in range(29):
        print("+ " + str(100 + i) + " " + str(100 + i) + " " + str(100 + i + 1))
        cnt -= 1
    # If 150 + n is zero, add 2^30 to 100 ~ 129

    print("< " + str(150 + n) + " 10000 10001")
    cnt -= 1
    for i in range(30):
        print("+ 10001 10001 10001")
        cnt -= 1
    for i in range(30):
        print("+ 10001 " + str(100 + i) + " " + str(100 + i))
        cnt -= 1


    # From 200 to 229, we store binary representation (2 ^ i) of A unless 150 + n is zero 

    for i in range(30):
        print("< " + str(2000 + i) + " " + str(2000 + i) + " " + str(2000 + i))
        cnt -= 1


    for i in range(29,-1,-1):
        print("< " + str(100 + i) + " 0 " + str(200 + i))
        cnt -= 1
        for j in range(i):
            print("+ " + str(200 + i) + " " + str(200 + i) + " " + str(200 + i))
            cnt -= 1
        for j in range(i):
            print("+ " + str(100 + j) + " " + str(200 + i) + " " + str(100 + j))
            cnt -= 1
    


    for i in range(30):
        print("+ " + str(300 + n) + " " + str(200 + i) + " " + str(300 + n))
        cnt -= 1

# Amplify values in 300 ~ 329 accordingly
for i in range(30):
    for j in range(i):
        print("+ " + str(300 + i) + " " + str(300 + i) + " " + str(300 + i))
        cnt -= 1
# Add them to 2
for i in range(30):
    print("+ " + str(300 + i) + " 2 2") 
    cnt -= 1

for i in range(cnt):
    print("< 100000 100000 100000")

Measured memory_bytes: 9180
s = input()
t = input()
ans = len(t)
for i in range(0, (len(s)-len(t)+1)):
    diff = 0
    for j in range(0, len(t)):
        if t[j] == s[i+j]:
            diff += 1
    ans = min(ans, len(t)-diff)
print(ans)

Measured memory_bytes: 9128
// #include <bits/stdc++.h>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<string>
#include<tuple>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}

inline void solve(void){
  string s;int w;
  in(s,w);
  for(int i=0;i*w<s.size();i++)cout<<s[i*w];
  cout<<endl;
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int dp[5030][5030];
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  reverse(rng(s));
  int ans = 0;
  rep(i,n){
    srep(j,i+1,n){
      if(s[i]==s[j])dp[i+1][j+1] = dp[i][j]+1;
      maxs(ans,min(dp[i+1][j+1],j-i));
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 70384
#include <bits/stdc++.h>
using namespace std;
int n, x;
const int MAXN = 100+10;
int ai[MAXN];
 
int main()
{
    scanf("%d%d", &n, &x);
    for(int i = 1; i <= n; i++)
        scanf("%d", &ai[i]);
    sort(ai+1, ai+n+1);
    int ans = 0;
    for(int i = 1; i <= n; i++)
    {
        if(x >= ai[i])
        {
            x -= ai[i];
            ai[i] = 0;
            ans ++;
        }
        else
            break;
    }
    if(x && ans && ai[n] == 0)
        ans--;
    printf("%d\n", ans);
    return 0;
}

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


int main() {

	int count = 0, count_max = 0;
	long int tmp;
	int i, j;

	long int N, Y;
	int x = -1, y = -1, z = -1;

	cin >> N;
	cin >> Y;
	
	for ( i = 0; i <= N; i++)
	{
		for ( j = 0; j <= N-i; j++)
		{
			tmp = i*5000 + j*1000 + (N-i-j)*10000;

			if (tmp == Y)
			{
				x = N - (i+j);
				y = i;
				z = j;
				i = N+1;
				break;
			}
			
		}
		
	}
	
	
	

	cout << x << " " <<  y << " " << z << " "  << endl;
	
		
	
	
}

Measured memory_bytes: 3636
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N, R; cin >> N >> R;
    if(N >= 10) cout << R << endl;
    else cout << R + 100 * (10 - N) << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
B = []
for a in A:
    if B:
        if B[-1] == a:
            continue
        else:
            B.append(a)
    else:
        B.append(a)

#print(B)
m = len(B)
X = []
for i in range(m):
    if i == 0:
        cur = B[0]
        cnt = 1
        flag = 0
    else:
        if flag == 0:
            if B[i] > cur:
                flag = 1
                cnt += 1
                cur = B[i]
            if B[i] < cur:
                flag = -1
                cnt += 1
                cur = B[i]
        elif flag == 1:
            if B[i] > cur:
                cnt += 1
                cur = B[i]
            else:
                X.append(cnt)
                cur = B[i]
                cnt = 1
                flag = 0
        else:
            if B[i] < cur:
                cnt += 1
                cur = B[i]
            else:
                X.append(cnt)
                cur = B[i]
                cnt = 1
                flag = 0
    #print(i, flag, cnt)
else:
    X.append(cnt)
#print(X)
print(len(X))


Measured memory_bytes: 63640
#include <bits/stdtr1c++.h>

#define min(a,b) (a<b?a:b)
using namespace std;


int start_x,start_y,end_x,end_y;

double a[1005][1005];
long long point[1005][3];
int n;
int main()
{
    cin>>start_x>>start_y>>end_x>>end_y;
    cin>>n;
    point[1][0]=start_x;point[1][1]=start_y;
    point[1][2]=0;
    for (int i=2;i<=n+1;i++)
    {
     long long tempx,tempy,tempr;
     cin>>tempx>>tempy>>tempr;
     point[i][0]=tempx;point[i][1]=tempy;
     point[i][2]=tempr;
    }
    point[n+2][0]=end_x;point[n+2][1]=end_y;
    point[n+2][2]=0;
    for (int i=1;i<=n+2;i++)
    {
     for (int j=1;j<=n+2;j++)
     {
       if (i==j) {a[i][j]=0.0;continue;}
       double dist=sqrt((point[i][0]-point[j][0])*(point[i][0]-point[j][0])
                       +(point[i][1]-point[j][1])*(point[i][1]-point[j][1]));
       if (point[i][2]+point[j][2]<dist)
        a[i][j]=dist-(point[i][2]+point[j][2]);
       else a[i][j]=0.0;
     }
    }
    for (int k=1;k<=n+2;k++)
      for (int i=1;i<=n+2;i++)
       for (int j=1;j<=n+2;j++)
        a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
    cout<<setprecision(11)<<a[1][n+2]<<endl;
    return 0;
}


Measured memory_bytes: 8192
using System;
using System.Linq;

namespace ABC138C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var values = Console.ReadLine().Split().Select(x => int.Parse(x)).OrderBy(x => x).ToArray();

            if (N == 2)
            {
                Console.WriteLine((double)values.Sum() / 2);
            }
            else
            {
                var ans = (double)values[0];
                for (var i = 1; i < N; i++)
                {
                    ans = (ans + values[i]) / 2;
                }
                Console.WriteLine(ans);
            }
        }
    }
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
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;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}



int main(){
    int n;cin >> n;
    double x[n+1];
    double y[n+1];
    vector<int> a(n);
    rep(i,n){ 
        cin >> x[i+1] >> y[i+1];
        a[i]=i+1;
    }

    double k=ka(n);
    double sum=0;
    for(int i=0;i<n-1;i++){
        sum+=sqrt(pow(x[a[i]]-x[a[i+1]],2)+pow(y[a[i]]-y[a[i+1]],2));
    }

    while(next_permutation(a.begin(),a.end())){
        for(int i=0;i<n-1;i++){
            sum+=sqrt(pow(x[a[i]]-x[a[i+1]],2)+pow(y[a[i]]-y[a[i+1]],2));
        }
    }
    double ans = sum/k;
    cout << setprecision(12) << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double

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

////////////////////////////////////////////////////////////////////
signed main(){
 int n,m;cin>>n>>m;
  if(n == 1 && m == 1)cout << 1;
  else if(n == 1)cout << m-2 << endl;
  else if(m == 1)cout << n-2 << endl;
  else cout << (n-2)*(m-2) << endl;
}


Measured memory_bytes: 256
main=do
 n<-readLn;a<-map read.words<$>getLine
 print(f n a (g n a 1) 0)
  where g 0 _ l = l
        g n (k:a) l = g (n-1) a (lcm k l)
        f 0 _ _ i = i
        f n (k:a) l i = f (n-1) a l (mod(i+(quot l k))1000000007)

Measured memory_bytes: 9468
n = int(input())
lis = list(map(int,input().split()))
li = list(map(int,input().split()))
ans = 0
for i in range(n):
    num = min(lis[i],li[i])
    ans += num
    lis[i] -= num
    li[i] -= num
    nu = min(lis[i+1],li[i])
    ans += nu
    lis[i+1] -= nu
    li[i] -= nu
print(ans)

Measured memory_bytes: 19116
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = getLine >>= print . solve

solve s = runST $ do
	let
		l = length s
	dp <- newArray ( ( 0, 0 ), ( l + 1, 12 ) ) 0 :: ST s ( STUArray s ( Int, Int ) Int )
	writeArray dp ( 0, 0 ) 1
	forM_ ( zip s [ 0 .. ] ) $ \( ch, i ) -> do
		forM_ [ 0 .. 12 ] $ \j -> do
			forM_ [ 0 .. 9 ] $ \k -> do
				when ( ch == '?' || digitToInt ch == k ) $ do
	 				modifyArray dp ( i + 1, ( j * 10 + k ) `mod` 13 ) =<< ( ( `mod` 1000000007 ) . ) . (+) <$> readArray dp ( i, j )
	readArray dp ( l, 5 )

Measured memory_bytes: 17788
#include <iostream>
using namespace std;
long n, s=1, M=1e9+7, a[1001];
int main() {
    int i,j,k;
	cin>>n;
	for(i=2;i<=n;i++){
	    k=i;
	    for(j=2;k>1;){
	        if(k%j==0){
	            a[j]++;
	            k/=j;
	        }
	        else
	            j++;
	    }
	}
	for(auto x:a)
	    s = s*(x+1)%M;
	cout<<s;
}

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

#define INF 1000000000;

int N;
int64_t A[100000];

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

    int64_t ansA = 0;
    int maxIndex;
    for(int i=0;i<N;i++){
        if( ansA < A[i] ){
            ansA = A[i];
            maxIndex = i;
        }
    }

    int64_t mini = INF;
    int64_t ansB;
    for(int i=0;i<N;i++){
        if( i != maxIndex && abs( ansA / 2 - A[i] ) < mini ){
            mini = abs( ansA / 2 - A[i] );
            ansB = A[i];
        }
    }

    cout << ansA << " " << ansB << endl;
}

Measured memory_bytes: 1024
s = int(input())

mod = 10**9 + 7
dp = [0]*(s+1)
dp[0] = 1
x = 0
for i in range(1,s+1):
    if i-3 >=0:
        x += dp[i-3]
        x %=mod
    dp[i] = x
        
print(dp[s])

Measured memory_bytes: 9180
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>

using namespace std;

const int INF = (1<<30) - 1;

const int P_MAX = 2000000;
vector<bool> is_prime(P_MAX, true);
vector<int> primes;
void sieve(){
    for(int i=2; i<P_MAX; i++){
        if(is_prime[i]){
            primes.push_back(i);
            for(int j=i*2; j<P_MAX; j+=i)
                is_prime[j] = false;
        }
    }
}

int main(){
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    
    sieve();
    
    int N, P;
    while(cin>>N>>P, (N>=0 && P>=0)){
        auto it = upper_bound(primes.begin(), primes.end(), N);
        vector<int> vec;
        for(auto i=it; i<it+P; i++){
            for(auto j=i; j<it+P; j++){
                vec.push_back((*i)+(*j));
            }
        }
        sort(vec.begin(), vec.end());
        cout << vec[P-1] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 2232
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

a,b = na()

if a==b:
    print(a+b)
else:
    print(max(a,b)*2-1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long 
#define ii pair<int,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define pw(x) (1<<(x))
#define inf 1000000005
#define MOD 1000000007 
#define N 100005
#define M 1000003
#define LOG 19
#define KOK 250
#define EPS 0.0000001
using namespace std;

int main() {

	int n;

	scanf("%d",&n);

	printf("%d",(n-2)*180);

}

Measured memory_bytes: 256
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

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

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;cin>>n;
    vector<int>x(n),y(n);vector<ll>h(n);
    for(int i=0;i<n;i++)
        cin>>x[i]>>y[i]>>h[i];
    ll cx,cy,H;
    for(cx=0;cx<=100;cx++){
        for(cy=0;cy<=100;cy++){
            H=-1;
            for(int i=0;i<n;i++){
                if(h[i]!=0){
                    if(H!=abs(cx-x[i])+abs(cy-y[i])+h[i]){
                        H=abs(cx-x[i])+abs(cy-y[i])+h[i];
                        int abc=1;
                        for(int j=0;j<n;j++){
                            if(h[j]!=(mmax(H-abs(cx-x[j])-abs(cy-y[j]),0)))
                                abc=0;
                        }
                        if(abc==1){
                            cout<<cx<<" "<<cy<<" "<<H<<endl;
                            return 0;
                        }
                    }
                }
            }
        }
    }

   /* for(int i=0;i<n;i++){
        if(h[i]==0){
            cout<<x[i]<<" "<<y[i]<<" "<<h[i]<<endl;
            return 0;
        }
    }*/
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------




Measured memory_bytes: 256
s=input()
fst,snd=s[:2],s[2:]
def m(s_):
    if int(s_) <= 12 and int(s_) > 0:
        return True
    return False

if m(fst) and m(snd):
    print("AMBIGUOUS")
elif m(fst):
    print("MMYY")
elif m(snd):
    print("YYMM")
else:
    print("NA")


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll a, b, x;
    cin >> a >> b >> x;
    double ans, t;
    if (2 * x > a * a * b)
    {
        t = (double)(2 * (a * a * b - x)) / (double) (a * a * a);
    }
    else
    {
        t = (double)(a * b * b) / (double)(2 * x);
    }
    ans = atan(t) * 180.0 / M_PI;
    
    cout << fixed;
    cout << setprecision(10) << ans << endl;
}


Measured memory_bytes: 512