akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll d[100009];
int main()
{
ll n;
cin>>n;
ll a[n+1];
for(int i=1;i<=n;i++)cin>>a[i];
ll c=1,an=0;
while(1)
{
    
if(c==2)break;
an++;
if(d[c]){an=-1;break;}
d[c]=1;
c=a[c];


}
cout<<an<<endl;

}

Measured memory_bytes: 5184
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef long long int lli;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<pll> vop;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define REP(i,a,b) for( long long i=a;i<b;i++)
#define REPR(i,a,b) for(long long i=a;i>=b;i--)
#define adb(a) for(auto ii:a) cout << ii << " "; cout << endl
#define adp(a) for(auto ii:a) cout << ii.F << " " << ii.S << endl;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define endl "\n"
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define PI 3.14159265358979323846
const ll MAXN = 100007;
const ll p = 1000000007;
#define N 100003
#define INF INTMAX_MAX

struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1> {}(p.first);
        auto hash2 = hash<T2> {}(p.second);
        return hash1 ^ hash2;
    }
};

ll dx[] = {1, -1, 0, 0};
ll dy[] = {0, 0, 1, -1};

ll power(ll a, ll b, ll m) { ll ans = 1; a = a % m; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; }

ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); }

ll modInverse(ll a, ll m) { ll g = __gcd(a, m); return power(a, m - 2, m); }

bool cmp(const pll &a, const pll &b)
{
    if (a.F != b.F) {
        return a.F > b.F;
    }
    else
        return a.S < b.S;
}

// bool check(ll i, ll j)
// {
//     if (i >= 0 && i < n && j >= 0 && j < m && a[i][j] != '#')
//         return true;
//     return false;
// }


int main()
{


    fastIO;
    int test = 1, num = 1;
    //cin >> test;
    while (test--)
    {
        string s, t;
        cin >> s >> t;
        ll ans = INTMAX_MAX;
        REP(i, 0, s.size())
        {
            ll r = 0;
            ll k = i;
            REP(j, 0, t.size())
            {
                if (k == s.size()) {
                    r = INTMAX_MAX;
                    break;
                }
                if (s[k] != t[j])
                    r++;
                k++;
            }
            ans = min(ans, r);
        }
        cout << ans;
    }
    return 0;
}

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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const string YES = "Yes";
const string NO = "No";

void solve(long long D, long long T, long long S) {
    if( S * T < D){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

int main() {
  long long D;
  scanf("%lld", &D);
  long long T;
  scanf("%lld", &T);
  long long S;
  scanf("%lld", &S);
  solve(D, T, S);
  return 0;
}


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

int n, m;
int a[1055], b[1055];

int inA[1000055];
int inB[1000055];

const int MOD = 1e9 + 7;

int row[1055], col[1055];

int main() {
	cin >> n >> m;
	
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		inA[a[i]] = i;
	}
	
	for (int i = 1; i <= m; i++) {
		cin >> b[i];
		inB[b[i]] = i;
	}
	
	int res = 1;
	int cRow = 0, cCol = 0;
	
	for (int i = n * m; i > 0; i--) {
		if (inA[i] && inB[i]) {
			row[inA[i]]++;
			col[inB[i]]++;
		} else if (inA[i]) {
			// column get covered
			
			res = (1ll * res * cCol) % MOD;
			row[inA[i]]++;
		} else if (inB[i]) {
			res = (1ll * res * cRow) % MOD;
			col[inB[i]]++;
		} else {
			res = (1ll * res * (cRow * cCol - (n * m - i))) % MOD;
		}
		
		if (row[inA[i]] == 1) {
			cRow++;
		}
		if (col[inB[i]] == 1) {
			cCol++;
		}
	}
	
	cout << res;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++)
        cin >> s[i];
    
    int ac = 0, wa = 0, tle = 0, re = 0;
    for (string t : s) {
        if (t == "AC")
            ac++;
        if (t == "WA")
            wa++;
        if (t == "TLE")
            tle++;
        if (t == "RE")
            re++;
    }
    
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    
    return 0;
}


Measured memory_bytes: 6424
/// Bismillahir Rahmanir Rahim

#include<bits/stdc++.h>

using namespace std;
using namespace __gnu_cxx;


#define FASTIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define IN freopen("input.txt","r+",stdin)
#define OUT freopen("output.txt", "w+", stdout)
#define DBG cout << "Hi there" << endl;
#define all(x) (x).begin(), (x).end()
#define fap(x) cout << " -- " << #x << ": " << (x) << "\n"
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))



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



const ll MAX= 998244353;
const ll MAX2=1271309838631957LL;
long double PI = acosl(-1);
const ll INF = 1e15;
const int NMAX = 1e5+5;
const int MAXLG = log2(NMAX)+1;
const int oo = 1e5+10;
const int sz = 100005;
const int MOD = 10000019;
const double EPS = 1e-9;

/// code starts from here

void solve(){
    string a, b;
    cin >> a >> b;

    int n = a.size();
    int m = b.size();
    vector<vector<int>> dp(n+1, vector<int>(m+1, 0));

    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= m; j++){
            if(i == 0 || j == 0)
                dp[i][j] = 0;
            else if(a[i-1] == b[j-1])
                dp[i][j] = dp[i-1][j-1]+1;
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }


    stack<char> s;
    int i = n, j = m;
    while(i > 0 && j > 0){
        if(a[i-1] == b[j-1]){
            i--;
            j--;
            s.push(a[i]);
        }
        else if(dp[i-1][j] > dp[i][j-1]){
            i--;
        }
        else
            j--;

    }

    while(!s.empty()){
        cout << s.top();
        s.pop();
    }

    cout << endl;

}

int main(){
    //#ifndef ONLINE_JUDGE
    //IN;
    //#endif
    FASTIO;
    int tc = 1;
    //cin >> tc;

    while(tc--){
        solve();
    }
}









Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
vector<int> e_e[100005] ;
vector<int> e_o[100005] ;
int color[100005] = {};
void dfs(int u){
    if(color[u]!=0)return;
    color[u] = 1;
    for(auto s:e_e[u]){
        dfs(s);
    }
    for(auto s:e_o[u]){
        dfs(s);
    }
}
int main() {
    int n,m;cin >> n >> m;
    int u,v,w;
    rep(i,n)color[i] = 0;
    rep(i,m){
        cin >> u >> v >> w;
        u--,v--;
        if(w&1){
            e_o[u].push_back(v);
            e_o[v].push_back(u);
        }else {
            e_e[u].push_back(v);
            e_e[v].push_back(u);
        }
    }
    int ans = 0;
    rep(i,n){
        if(color[i])continue;
        ans++;
        dfs(i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 13184
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <regex>
#include <list>
int main() {
	std::string s;
	std::cin >> s;
	int month = (s[0]-'0') * 10 + s[1]-'0';
	int year = (s[2]-'0') * 10 + s[3]-'0';
	if (0 < month && month <= 12 && 0 < year && year <= 12) {
		std::cout << "AMBIGUOUS" << std::endl;
	}
	else if (0 < month && month <= 12) {
		std::cout << "MMYY" << std::endl;
	}
	else if (0 < year && year <= 12) {
		std::cout << "YYMM" << std::endl;
	}
	else {
		std::cout << "NA" << std::endl;
	}
	return 0;
}

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

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>

int main()
{
    int a[3], cnt = 0;

    rep(i, 0, 3) cin >> a[i];
    sort(a, a + 3);
    while (1)
    {
        if (a[0] == a[1] && a[1] == a[2])
            break;
        if (a[0] + 2 <= a[1])
        {
            a[0] += 2;
        }
        else
        {
            a[0]++;
            a[1]++;
        }
        sort(a, a + 3);
        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <vector>

int main () {
  int N, C;
  std::cin >> N >> C;

  // Dとcの設定
  int ** D = new int * [C];
  int ** c = new int * [3];
  for (int i = 0; i < C; i++ ) {
    D[i] = new int[C];  
  }
  for (int i = 0; i < 3; i++ ) {
    c[i] = new int[C];  
  }
  for (int i = 0; i < C; i++ ) {
    for (int j = 0; j < C; j++ ) {
      std::cin >> D[i][j];  
    }  
  }
  for (int i = 0; i < 3; i++ ) {
    for (int j = 0; j < C; j++) {
      c[i][j] = 0;   
    }  
  }


  // 3の剰余によって場合分け
  // 例えば, 1 1が入ってきた時c[2][値-1]に++される.
  int sub = 0;
  for (int i = 0; i < N; i++ ) {
    for (int j = 0; j < N; j++ ) {
      if ((i + j + 2) % 3 == 0 ) {
        std::cin >> sub;
        c[0][sub-1]++;  
      }
      else {
        if ((i + j + 2) % 3 == 1) {
          std::cin >> sub;
          c[1][sub-1]++;  
        }  
        else {
          std::cin >> sub;
          c[2][sub-1]++;  
        }
      }
    }  
  }

  // Cの色から3色選び, それについて直した時の違和感の合計を調べて行く. 
  // 計算量ワンチャンヤバい気がする.
  int answer = -1;
  int sub_answer = 0;
  bool forBool = false;
  
  // 3の剰余によって分類すべきでしたね.
  for (int i = 0; i < C; i++ ) {
    for (int j = 0; j < C; j++ ) {
      for (int k = 0; k < C; k++ ) {
        sub_answer = 0;
        forBool = false;
        if (i != j && j != k && k != i ) {
          
          // c[0]から見て行く.
          for (int l = 0; l < 3; l++ ) {
            for (int m = 0; m < C; m++) {
              if (answer >= 0 && sub_answer >= answer ) {
                forBool = true;
                break;  
              }
              if (l == 0) {
                sub_answer = sub_answer + c[l][m]*D[m][i];
              }
              else {
                if (l == 1) {
                  sub_answer = sub_answer + c[l][m]*D[m][j];  
                }  
                else {
                  sub_answer = sub_answer + c[l][m]*D[m][k];  
                }
              } 
            }
            if (forBool) {
              break;  
            }    
          } 
          if (answer < 0 || sub_answer <= answer ) {
            answer = sub_answer;  
          } 
        } 
      }  
    }  
  }

  std::cout << answer << std::endl;

  // deleteすることを忘れずに
  for (int i = 0; i < C; i++ ) {
    delete[] D[i];
    D[i] = 0;  
  }
  for (int i = 0; i < 3; i++ ) {
    delete[] c[i];
    c[i] = 0;  
  }
  delete[] D;
  D = 0;
  delete[] c;
  c = 0;
  return 0;
}


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

#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++)

using namespace std;
const long long INF = 1LL << 61;

int main() {
	int N; cin >> N;
	int ans = 0;
	bool flag = true;
	int keta = 1;
	rep(i, N) {
		if (10 * keta == i + 1) {
			keta *= 10;
			flag = !flag;
		}
		if (flag)++ans;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,A,B;
  cin >> N;
  
  int num=0;

  for (int i = 0; i < N; i++){
      cin >> A >> B;
    num += B-A+1;
  }
  
  cout << num << endl;
    
 
}

Measured memory_bytes: 3596
//#include <bits/stdc++.h>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <bitset>
#include <array>
#include <set>
#include <string>

#include <iterator>
#include <algorithm>
#include <numeric>

#include <ios>
#include <sstream>
#include <iostream>
#include <fstream>

#include <climits>
#include <cmath>

using namespace std;

#define EPS (1e-7)
#define MOD ((int)1e9+7)
#define PI (atan(1.0)*4)

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

void OUT(bool isTrue, string t="YES", string f="NO"){
    cout<<(isTrue?t:f)<<endl;
}
void Out(bool isTrue, string t="Yes", string f="No"){
    cout<<(isTrue?t:f)<<endl;
}
void out(bool isTrue, string t="yes", string f="no"){
    cout<<(isTrue?t:f)<<endl;
}
void bulk(){}
template <class Head, class... Tail>
void bulk(Head& head, Tail&... tail){
    cin>>head;
    bulk(tail...);
}
template <typename T>
string printItr(T b, T e, string delim=" ")
{
    stringstream ss;
    ostream_iterator<decltype(*b)> out_it(ss, delim.c_str());
    copy(b,e - 1, out_it);
    ss<<*(e-1);
    return ss.str();
}

#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define range(i,m,n) for(int i=m; i<n;i++)
#define each(i,n) for(auto i:n)
#define all(i) i.begin(),i.end()
#define cint(...) int __VA_ARGS__;bulk(__VA_ARGS__);


int main(void){
    cint(n);
    cout<<(int)pow(floor(sqrt(n)),2);
}

Measured memory_bytes: 256
/// Bismillahir Rahmanir Rahim
/* Mohammad Morsalin
   Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define int long long
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ms2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pi pair<int,int>
#define tc(t) int t;cin>>t;while(t--)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define fi first
#define se second
#define PI acos(-1)
#define sz(a) (int)a.size();
#define IOS ios::sync_with_stdio(false);
using namespace std;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
double sq(double x) {return x*x;}
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
signed main()
{
    IOS
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int times=0;
    while(a>=b){
        b*=2;
        times++;
    }
    while(b>=c){
        c*=2;
        times++;
    }
    if(times<=k)cout << "Yes\n";
    else cout << "No\n";

    return 0;
}
///Alhamdulillah


Measured memory_bytes: 3648
#include<bits/stdc++.h>
clock_t t=clock();
namespace my_std{
	using namespace std;
	#define pii pair<int,int>
	#define fir first
	#define sec second
	#define MP make_pair
	#define rep(i,x,y) for (int i=(x);i<=(y);i++)
	#define drep(i,x,y) for (int i=(x);i>=(y);i--)
	#define go(x) for (int i=head[x];i;i=edge[i].nxt)
	#define templ template<typename T>
	#define sz 3333
	#define mod 998244353ll
	typedef long long ll;
	typedef double db;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
	templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
	templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
	templ inline void read(T& t)
	{
		t=0;char f=0,ch=getchar();double d=0.1;
		while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
		while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
		if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
		t=(f?-t:t);
	}
	template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
	char __sr[1<<21],__z[20];int __C=-1,__zz=0;
	inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
	inline void print(register int x)
	{
		if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
		while(__z[++__zz]=x%10+48,x/=10);
		while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
	}
	void file()
	{
		#ifdef NTFOrz
		freopen("a.in","r",stdin);
		#endif
	}
	inline void chktime()
	{
		#ifdef NTFOrz
		cout<<(clock()-t)/1000.0<<'\n';
		#endif
	}
	#ifdef mod
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
	ll inv(ll x){return ksm(x,mod-2);}
	#else
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
	#endif
//	inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

int n,X;
ll C[sz][sz];
ll f[sz][sz<<1];

int main()
{
	file();
	read(n,X);
	f[0][0]=1;
	rep(i,0,sz-5) rep(j,0,sz*2-5) (f[i+1][j]+=f[i][j])%=mod,(f[i+1][j+1]+=f[i][j])%=mod,(f[i+1][j+2]+=f[i][j])%=mod;
	rep(i,0,sz-1) C[i][0]=1;
	rep(i,1,sz-1) rep(j,1,i) (C[i][j]=C[i-1][j]+C[i-1][j-1])%=mod;
	ll ans=0;
	rep(i,0,X-1) (ans+=f[n][i])%=mod;
	rep(j,0,n-1) for (int k=1;X-2*k-1>=0&&k*2<=n-j;k++) (ans+=C[n-j-1][k*2-1]*f[j][X-2*k-1]%mod)%=mod;
	if (X&1) rep(i,X/2+X/2+1,n) (ans+=C[n][i])%=mod;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 262400
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 3010, P = 1000000007;

int n;
int dp[N];
char s[N];

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  scanf("%d%s", &n, s + 1);
  dp[1] = 1;
  for (int i = 1; i < n; ++i)
    if (s[i] == '<') {
      memmove(dp + 2, dp + 1, sizeof(int) * i);
      dp[1] = 0;
      for (int j = 2; j <= i + 1; ++j)
        if ((dp[j] += dp[j - 1]) >= P)
          dp[j] -= P;
    } else {
      for (int j = i; j; --j)
        if ((dp[j] += dp[j + 1]) >= P)
          dp[j] -= P;
    }
  printf("%d\n", int(accumulate(dp + 1, dp + n + 1, 0LL) % P));

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


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

using namespace std;

#define MAX 82
bool dp[MAX][MAX][MAX*MAX*4];
int a[MAX][MAX], b[MAX][MAX];
int x[MAX][MAX], y[MAX][MAX];

int main()
{
    //freopen("in.txt", "r", stdin);
    int n, m;
    scanf("%d %d", &n, &m);
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            scanf("%d", &a[i][j]);
        }
    }
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            scanf("%d", &b[i][j]);
            x[i][j] = a[i][j]-b[i][j]+80;
            y[i][j] = b[i][j]-a[i][j]+80;
        }
    }
    memset(dp, false, sizeof dp);
    dp[1][1][x[1][1]] = true;
    dp[1][1][y[1][1]] = true;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            if(i == 1 && j == 1) continue;
            int val1 = x[i][j], val2 = y[i][j];
            for(int num=0; num<MAX*MAX*2; num++){
                if(num-val1 >= 0 && dp[i-1][j][num-val1]) dp[i][j][num] = true;
                if(num-val2 >= 0 && dp[i-1][j][num-val2]) dp[i][j][num] = true;
                if(num-val1 >= 0 && dp[i][j-1][num-val1]) dp[i][j][num] = true;
                if(num-val2 >= 0 && dp[i][j-1][num-val2]) dp[i][j][num] = true;
            }
        }
    }
    int len = n+m-1;
    int mins = MAX*MAX*2;
    for(int num=0; num<MAX*MAX*2; num++){
        if(dp[n][m][num]){
            int val = num-80*len;
            if(val < 0) val = val*-1;
            mins = min(mins, val);
        }
    }
    cout << mins;
}

Measured memory_bytes: 177024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			int n = sc.nextInt();
			long power = 1;
			for (int i = 1; i <= n; i++) {
				power = i * power % 1000000007;
			}

			System.out.println(power);

		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 21844
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 4e18;

int main() {
    int n,m,k; scanf("%d", &n);
    for (m = 1; m * m <= 8 * n + 1; m+=2) {
        if (m * m == 8 * n + 1) {
            break;
        }
    }
    if (m * m == 8 * n + 1) {
        k = (m + 1) / 2;
        vector<vector<int>> out(k + 1);
        puts("Yes");
        cout << k << endl;
        int index = 1;
        REP(i, k) {
            printf("%d ", k-1);
            REP(j, k-1) {
                if (j >= out[i].size()) {
                    printf("%d ",index);
                    out[i + j - out[i].size() + 1].push_back(index);
                    index++;
                }
                else {
                    printf("%d ", out[i][j]);
                }
            }
            printf("\n");
        }
    }
    else {
        puts("No");
    }
    getchar(); getchar();
}

Measured memory_bytes: 1920
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
	if(!b)return 1;	if(b&1)return modpow(a,b-1,m)*a%m;
	int memo = modpow(a,b>>1,m);
	return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  rep(i,c){
  if(i%2==0){
    if(a%2==0){
      a/=2;
      b+=a;
    }
      else{
      a--;
        a/=2;
        b+=a;
      }
        
  }
    else{
     if(b%2==0){
      b/=2;
      a+=b;
    }
      else{
      b--;
        b/=2;
        a+=b;
      }
    }
  }
    cout<<a<<' '<<b<<endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>//万能头文件 
using namespace std;//命名空间 
long long int n;//定义海拔 
char s;//定义输入 
long long int ans=0;//输出 
long long int ansn=0;//用来存储小答案
int main(){//主函数 
    cin>>n;//输入不解释 
    for(int i=1;i<=n;i++){
        cin>>s;//输入I或D 
        if(s=='I'){
            ansn++;//如果为I，ansn++ 
        }
        else if(s=='D'){
            ansn--;//如果为D，ansn-- 
        }
        ans=max(ans,ansn);//求ans与ansn两个之间的大值 
    }
    cout<<ans;//输出答案 
    return 0;//结束程序 
} //真好 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// 無限大の値
const ll  LINF = 1LL << 60;
const int iINF = 1 << 29;

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

  cout << s.substr(0,5) + " " + s.substr(6,7) + " " + s.substr(14);
}

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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define debug(x) cout << #x << " : " << x << '\n'

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

  string ans;
  int N;
  cin >> N;

  if (!N) {
    ans = "0";
  }

  int temp;
  while (N) {
    if (N % 2 == -1) {
      ans.push_back('1');
      N -= 1;
    } else {
      char c = '0' + N % (-2);
      ans.push_back(c);
    }

    N = N / (-2);
  }

  reverse(ALL(ans));

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List
import Data.List.Split (splitOn)
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IM

main :: IO ()
main = do
  n <- readLn
  unless (n == 0) $ do
    solve <$> replicateM n f >>= print
    main
  where
    f = map toSec <$> words <$> getLine

solve :: [[Int]] -> Int
solve = fst . IM.foldl' f (0, 0) . foldl' g IM.empty
  where
    f (mxc, acc) x = let x' = acc + x
                     in (max mxc x', x')
    g m [lt, at] = IM.insertWith (+) lt 1 (IM.insertWith (+) at (-1) m)

toSec :: String -> Int
toSec = sum . zipWith (*) [3600, 60, 1] . map read . splitOn ":"



Measured memory_bytes: 16504
import java.util.*;

public class Main {

    public static void main(String[] args) {

    	Scanner sc = new Scanner(System.in);
    	String s = sc.next();
        boolean isOK = true;

        for (int i = 1; i <= s.length(); i++) {
            char c = s.charAt(i-1);
            if (i % 2 == 0) {
                if (c != 'L' && c != 'U' && c != 'D'){
                    isOK = false;
                    break;
                }
            } else {
                if (c != 'R' && c != 'U' && c != 'D'){
                    isOK = false;
                    break;
                }
            }
        }
        if (isOK)
            System.out.println("Yes");
        else 
            System.out.println("No");
   	}
}

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

int main()
{
	int i=0,n,ww,h[100], w[100];

	cin >> h[0] >> w[0];

	while ((h[i] != 0) && (w[i] != 0)) {
		i++;
		cin >> h[i] >> w[i];
	}

	n = i;
	i = 0;	

	while(i < n) {
		while(h[i]--) {
			ww = w[i];
			while(ww--)
				cout << '#';
			cout << endl;
		}
		cout << endl;
		i++;
	}	
	return 0;
}

Measured memory_bytes: 3036
#include "bits/stdc++.h"

using namespace std;

#define ll                     long long int
#define endl                   '\n'

static const int maxn = 2e5 + 5;

int sum[maxn][27];

signed main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);
      cout.tie(nullptr);
      cout << fixed << setprecision(8);


      string s, t;
      cin >> s >> t;
      int lens = s.size();
      int lent = t.size();
      for (int i = 1; i <= lens; i++)
      {
            sum[i][ s[i - 1] - 'a' + 1 ]++;
            for (int j = 1; j <= 26; j++) sum[i][j] += sum[i-1][j];
      }
      for (int i = 0; i < lent; i++)
      {
            int val = t[i] - 'a' + 1;
            if (sum[lens][val] == 0)
            {
                  cout << -1 << endl;
                  return 0;
            }
      }
      ll res = 0;
      int last = 0;
      for (int i = 0; i < lent; i++)
      {
            int val = t[i] - 'a' + 1;
            int lo = last + 1;
            int hi = lens;
            if (lo > hi)
            {
                  last = 0;
                  lo = last + 1;
                  hi = lens;
            }
            int ans = -1;
            while (lo <= hi)
            {
                  int mid = lo + hi >> 1;
                  int cumsum = sum[mid][val] - sum[last][val];
                  if (cumsum > 0) ans = mid, hi = mid - 1;
                  else lo = mid + 1;
            }
            if (ans != -1)
            {
              //    cerr << i << " " << last << " - " << ans << endl;
                  res += (ans - last);
                  last = ans;
                  continue;
            }
            res += (lens - last);
            last = 0;
            lo = last + 1;
            hi = lens;
            ans = -1;
            while (lo <= hi)
            {
                  int mid = lo + hi >> 1;
                  int cumsum = sum[mid][val] - sum[last][val];
                  if (cumsum > 0) ans = mid, hi = mid - 1;
                  else lo = mid + 1;
            }
            assert(ans != -1);
            //cerr << i << " ---- " << last << " - " << ans << endl;
            res += (ans - last);
            last = ans;
      }
      cout << res << endl;
}


Measured memory_bytes: 12880
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn main() {
    input!{
        n: usize,
        s_vec: [String; n],
    }

    let alphabet: Vec<char> = (97..97+26).map(|x| std::char::from_u32(x).unwrap()).collect();

    let mut map: HashMap<char, usize> = HashMap::new();
    
    for c in alphabet.into_iter() {
        let mut char_cnt: Vec<usize> = Vec::new();
        for s in s_vec.iter() {
            let mut cnt = 0;
            for sc in s.chars() {
                if c == sc {
                    cnt += 1;
                }
            }
            char_cnt.push(cnt)
        }
        let min_cnt = char_cnt.iter().min().unwrap();
        if *min_cnt != 0 {
            map.insert(c, *min_cnt);
        }
    }
    let mut ans: Vec<char> = Vec::new();

    for (k, v) in map.into_iter() {
        for _ in 0..v {
            ans.push(k)
        }
    }
    ans.sort();
    println!("{}", ans.iter().collect::<String>());
}


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

namespace kakomon
{
    class Program
    {
        static void Main(string[] args)
        {
            agc004_a();
        }

        static void agc004_a()
        {
            // A - Divide a Cuboid
            long[] size = Console.ReadLine().Trim().Split().Select(long.Parse).ToArray();
            long ans;
            // 3サイズのうち1辺でも偶数があれば、ちょうど半分にできて、差は0
            if (size.Where(x => x % 2 == 0).Count() > 0)
            {
                ans = 0;
            }
            // そうでない、3辺とも奇数長さの場合は、短いほう2辺の積(1層分)が差の最小値
            else
            {
                Array.Sort(size);
                ans = size[0] * size[1];
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13652
#include <iostream>
using namespace std;
int main() {
    int a,b;
    cin>>a>>b;
    if(a==b){cout<<"a == b"<<endl;}else{
    if(a>b){
        cout<<"a > b"<<endl;}
    else{
        cout<<"a < b"<<endl;}
    }
return 0;
}

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
const int maxn = 1e6+5;
long long arr[maxn];

int main(){
    int a,b,c,d,i,n;
    cin>>a>>b>>c>>d;
    if(c>=b){
        cout<<0;
    }
    else if(d<=a){
        cout<<0;
    }
    else{
        i = max(a,c);
        n = min(b,d);
        cout<<n-i;
    }
}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

const int INF = 2147483647;
//const ll LINF = ll();今度書く

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main() {

	int a, b, k, maxofmin;
	scanf("%d%d%d", &a, &b, &k);
	for (int i = a; i < min(a + k, b + 1); ++i) {
		printf("%d\n", i);
		if (i + 1 >= min(a + k, b + 1))maxofmin = i;
	}
	for (int i = max(b - k + 1, a); i <= b; ++i) {
		if (i > maxofmin)printf("%d\n", i);
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <string>

using namespace std;

string message[] = {"Opened by ", "Closed by "};
int cnt;
int n, m;
set<string> registered;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        string str;
        cin >> str;
        registered.insert(str);
    }

    cin >> m;
    for (int i = 0; i < m; i++) {
        string str;
        cin >> str;
        if (registered.count(str) == 0) {
            cout << "Unknown " << str << endl;
        } else {
            cout << message[cnt % 2] << str << endl;
            cnt++;
        }
    }

    return 0;
}

Measured memory_bytes: 3216
int main(void) {
  int MM[100][100];
 
  int n, a, b, v, i, j;
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ) {
    for ( j = 0; j < n; j++ ) MM[i][j] = 0;
    }

  for ( i = 0; i < n; i++ ) {
    scanf("%d %d", &a, &b);
      a--;
      for ( j = 0; j < b; j++ ) {
        scanf("%d", &v);
          v--;
            MM[a][v] = 1;
        }
    }
 
  for ( i = 0; i < n; i++ ) {
    for ( j = 0; j < n; j++ ) {
      if ( j ) printf(" ");
        printf("%d", MM[i][j]);
        }
        
  printf("\n");
   }
  
  return 0;

}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

int main()
{
  int a,b;
  cin >> a >> b;
  int result = -1;
  if(a <= 9 && b <= 9){
    result = a*b;
  }
  cout << result << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int a, b, c, d,e;
	cin >> a >> b >> c >> d;
	if (a > c) {
		e = a;
		a = c;
		c = e;
	}
	if (c > b&&b > a) {
		if (c - b <= d && b - a <= d)
			cout << "Yes";
		else
			cout << "No";
	}
	else if (c - a <= d)
		cout << "Yes";
	else
		cout << "No";
}

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

using lint = long long int;
using pii = std::pair<int, int>;
using pll = std::pair<lint, lint>;
using node = std::pair<lint, pll>;

using std::vector;
using std::min;
using std::max;
using data_type = int;

class Union_Find {
public:
	vector<data_type> ve;
	vector<data_type> level;

	void init(data_type size); // vector 초기화
	data_type find(data_type num); // 값을 찾아주는 함수
	void merge(data_type num1, data_type num2); // 그룹 결합
};
void Union_Find::init(data_type size) {
	ve.clear();
	level.clear();

	for (data_type i = 0; i <= size; i++) {
		ve.push_back(i);
		level.push_back(1);
	}
}
data_type Union_Find::find(data_type num) {
	int temp = num;
	while (ve[num] != num) {
		num = ve[num];
	}
	ve[temp] = num;
	return num;
}
void Union_Find::merge(data_type num1, data_type num2) {
	num1 = find(num1);
	num2 = find(num2);
	if (num1 == num2) {
		return;
	}

	if (level[num1] >= level[num2]) {
		ve[num2] = num1;
		level[num1] = max(level[num1], 1 + level[num2]);
	}
	else {
		ve[num1] = num2;
		level[num2] = max(level[num2], 1 + level[num1]);
	}
}

vector<pll> ve[2];
vector<node> real[2];

int main(void) {
	int N;
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		lint t1, t2;
		scanf("%lld %lld", &t1, &t2);
		ve[0].push_back(pll(t1, i));
		ve[1].push_back(pll(t2, i));
	}
	sort(ve[0].begin(), ve[0].end());
	sort(ve[1].begin(), ve[1].end());
	for (int i = 0; i < N - 1; i++) {
		real[0].push_back(node(ve[0][i + 1].first - ve[0][i].first, pll(ve[0][i].second, ve[0][i + 1].second)));
		real[1].push_back(node(ve[1][i + 1].first - ve[1][i].first, pll(ve[1][i].second, ve[1][i + 1].second)));
	}
	sort(real[0].begin(), real[0].end());
	sort(real[1].begin(), real[1].end());

	Union_Find temp;
	temp.init(N);

	int ind1 = 0, ind2 = 0, cou = 1;
	lint ans = 0;
	while (cou < N) {
		int cur1, cur2, val;
		if (real[0][ind1].first < real[1][ind2].first) {
			cur1 = real[0][ind1].second.first;
			cur2 = real[0][ind1].second.second;
			val = real[0][ind1].first;
			ind1++;
		}
		else {
			cur1 = real[1][ind2].second.first;
			cur2 = real[1][ind2].second.second;
			val = real[1][ind2].first;
			ind2++;
		}
		if (temp.find(cur1) != temp.find(cur2)) {
			cou++;
			temp.merge(cur1, cur2);
			ans += val;
		}
	}

	printf("%lld", ans);

	return 0;
}

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

using namespace std;

#define N 800000

int n,m,ans,a[N],f[N],cnt[2][N],seg[2][N];
struct node{
	int l,r;
	bool operator < (const node p) const{return l<p.l;}
}b[N];

#define ls (x<<1)
#define rs (x<<1|1)

void build(int x,int l,int r){
	if (l==r){seg[0][x]=seg[1][x]=n; return;}
	int mid=(l+r)>>1;
	build(ls,l,mid); build(rs,mid+1,r);
	seg[0][x]=min(seg[0][ls],seg[0][rs]);
	seg[1][x]=min(seg[1][ls],seg[1][rs]);
}

void mdf(int x,int l,int r,int k,int t){
	if (l==r){
		seg[0][x]=min(seg[0][x],t-cnt[0][k]);
		seg[1][x]=min(seg[1][x],t-cnt[1][k]);
		return;
	}
	int mid=(l+r)>>1;
	if (k<=mid) mdf(ls,l,mid,k,t); else mdf(rs,mid+1,r,k,t);
	seg[0][x]=min(seg[0][ls],seg[0][rs]);
	seg[1][x]=min(seg[1][ls],seg[1][rs]);
}

int qry(int s[],int x,int l,int r,int L,int R){
	if (L>R) return n;
	if (l>=L&&r<=R) return s[x];
	int mid=(l+r)>>1,ret=n;
	if (L<=mid) ret=min(ret,qry(s,ls,l,mid,L,R));
	if (R>mid) ret=min(ret,qry(s,rs,mid+1,r,L,R));
	return ret;
}

#undef ls
#undef rs

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		cnt[0][i]=cnt[0][i-1]+(a[i]==0);
		cnt[1][i]=cnt[1][i-1]+(a[i]==1);
	}
	scanf("%d",&m);
	for (int i=1;i<=m;i++) scanf("%d%d",&b[i].l,&b[i].r);
	sort(b+1,b+m+1);
	memset(f,0x3f,sizeof f); f[0]=0;
	build(1,1,n); ans=cnt[1][n];
	for (int i=1;i<=m;i++){
		int l=b[i].l,r=b[i].r;
		f[r]=cnt[1][l-1]+cnt[0][r]-cnt[0][l-1];
		f[r]=min(f[r],qry(seg[1],1,1,n,1,l-1)+cnt[1][l-1]+cnt[0][r]-cnt[0][l-1]);
		f[r]=min(f[r],qry(seg[0],1,1,n,l,r)+cnt[0][r]);
		mdf(1,1,n,r,f[r]);
		ans=min(ans,f[r]+cnt[1][n]-cnt[1][r]);
	}
	printf("%d\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 20352
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	private static final int NUM = 3;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int[] a = new int[NUM];
			IntStream.range(0, NUM).forEach(i -> a[i] = scanner.nextInt());
			int sum = Arrays.stream(a).sum();
			int max = Arrays.stream(a).max().getAsInt();
			System.out.println((sum == max + max) ? "Yes" : "No");
		}
	}
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

bool visit(const Graph &g, int v, vi &order, vi &color)
{
  color[v] = 1;
  vrep(e, g[v]) {
    if (color[e->dst] == 2) continue;
    if (color[e->dst] == 1) return false;
    if (!visit(g, e->dst, order, color)) return false;
  }
  order.push_back(v); color[v] = 2;
  return true;
}

bool TopologicalSort(const Graph &g)
{
  int n = g.size();
  vi color(n);
  vi order(n);
  rep(u, n) if (!color[u] && !visit(g, u, order, color)) return false;
  return true;
}

int V, E;
int s, t;

int main()
{
  cin >> V >> E;
  Graph g(V);
  rep(i, E){
    cin >> s >> t;
    g[s].pb(Edge(s, t, 1));
  }

  puts(!TopologicalSort(g) ? "1" : "0");

  return 0;
}

Measured memory_bytes: 1188
import sys
import math
input = sys.stdin.readline


def eratosthenes(n):
    if n % 2 == 0:
        is_prime = [False, True] * (n // 2)
        is_prime.append(False)
    else:
        is_prime = [False, True] * ((n + 1) // 2)
    if n >= 1:
        is_prime[1] = False
    if n >= 2:
        is_prime[2] = True

    for i in range(3, n + 1, 2):
        if i * i > n:
            break
        if is_prime[i]:
            for j in range((n - i * i) // i + 1):
                is_prime[i * i + i * j] = False
    return is_prime


q = int(input())
l = []
r = []
for i in range(q):
    li, ri = map(int, input().split())
    l.append(li)
    r.append(ri)

r_max = max(r)
is_prime = eratosthenes(r_max)
a = [0] * (r_max + 1)
for i in range(3, r_max + 1):
    a[i] = a[i - 1]
    if is_prime[i] and is_prime[(i + 1) // 2]:
        a[i] += 1
# print(a)

for i in range(q):
    print(a[r[i]] - a[l[i] - 1])


Measured memory_bytes: 13376
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;
ll n,m;
string s;
ll dp[1000001];
ll ans=0;
int main()
{while(1){
	memset(dp,0,sizeof(dp));
	cin>>n;
	if(!n) break;
	cin>>m>>s;
	ans=0;
	for(ll i=0;i<m;i++){
		if(i>0&&s[i-1]!=s[i]){
				dp[i]=dp[i-1]+1;
		}
		else if(s[i]=='I') dp[i]=1;
		
		if(s[i]=='I'&&dp[i]>2*n){
			ans++;
		}
	}
	cout<<ans<<endl;
}
}

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

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int n, j, ans, a[100000], l[100000], r[100000];
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	l[0] = a[0];
	r[n - 1] = a[n - 1];
	rep(i, n - 1) {
		l[i + 1] = gcd(l[i], a[i + 1]);
		j = n - 2 - i;
		r[j] = gcd(r[j + 1], a[j]);
	}
	rep(i, n) {
		if (i == 0) {
			ans = r[i + 1];
		}
		else if (i == n - 1) {
			ans = max(ans, l[i - 1]);
		}
		else {
			ans = max(ans, gcd(l[i - 1], r[i + 1]));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 2560
use num::traits::One;
use proconio::input;
use std::{
    fmt,
    iter::Sum,
    ops::{Add, Mul, Neg},
};

fn main() {
    input! {
        k: usize,
        s: String,
    }

    let binomial = Znz::binomial_table(k + s.len());

    let ans = (0..=k)
        .map(|t| {
            num::pow(Znz::new(25), k - t)
                * num::pow(Znz::new(26), t)
                * binomial(s.len() + k - t - 1, s.len() - 1)
        })
        .sum::<Znz>();

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

#[derive(Clone, Copy, Debug)]
struct Znz {
    repr: usize,
}

impl Znz {
    const MODULUS: usize = 1_000_000_007;

    fn binomial_table(max: usize) -> impl Fn(usize, usize) -> Self {
        let mut fact = vec![Self::new(0); max + 1];
        let mut fact_inv = vec![Self::new(0); max + 1];
        let mut inv = vec![Self::new(0); max + 1];

        fact[0] = Self::new(1);
        fact[1] = Self::new(1);
        fact_inv[0] = Self::new(1);
        fact_inv[1] = Self::new(1);
        inv[1] = Self::new(1);

        for i in 2..=max {
            fact[i] = fact[i - 1] * Self::new(i);
            inv[i] = -inv[Self::MODULUS % i] * Self::new(Self::MODULUS / i);
            fact_inv[i] = fact_inv[i - 1] * inv[i];
        }

        move |n: usize, k: usize| -> _ {
            if n < k {
                Self::new(0)
            } else {
                fact[n] * fact_inv[k] * fact_inv[n - k]
            }
        }
    }

    fn new(val: usize) -> Self {
        Self {
            repr: val % Self::MODULUS,
        }
    }
}

impl fmt::Display for Znz {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        fmt::Display::fmt(&self.repr, fmt)
    }
}

impl Neg for Znz {
    type Output = Self;

    fn neg(self) -> Self {
        Self::new(Self::MODULUS - self.repr)
    }
}

impl Add for Znz {
    type Output = Self;

    fn add(self, rhs: Self) -> Self {
        Self::new(self.repr + rhs.repr)
    }
}

impl Mul for Znz {
    type Output = Self;

    fn mul(self, rhs: Self) -> Self {
        Self::new(self.repr * rhs.repr)
    }
}

impl Sum for Znz {
    fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
        iter.fold(Znz::new(0), Add::add)
    }
}

impl One for Znz {
    fn one() -> Self {
        Self { repr: 1 }
    }
}


Measured memory_bytes: 50944
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 2e5 + 100;
typedef long long ll;

int n, m;

int f[N], siz[N];
int find(int x) {
	return f[x] == x ? x : f[x] = find(f[x]);
}
void merge(int x, int y) {
	x = find(x), y = find(y);
	if(x == y) return;
	f[x] = y;
	siz[y] += siz[x];
}
int main() {
	
	cin >> n >> m;
	
	for(int i = 1; i <= n; i++) {
		f[i] = i;
		siz[i] = 1;
	}
	
	for(int i = 1; i <= m; i++) {
		int x, y;
		scanf("%d %d", &x, &y);
		merge(x, y);
	}
	
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		ans = max(ans, siz[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4780