akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int main(void)
{
    int n,t,m=INT_MAX,i;
    scanf("%d",&n);
    char *s=calloc(n+1,sizeof(char));
    int *te=calloc(n,sizeof(int)),*tw=calloc(n,sizeof(int));
    scanf("%s",s);
    if(s[0]=='E')te[0]++;
    else tw[0]++;
    for(i=1;i<n;i++){
        if(s[i]=='E'){
            te[i]=te[i-1]+1;
            tw[i]=tw[i-1];
        }
        else{
            te[i]=te[i-1];
            tw[i]=tw[i-1]+1;
        }
    }
    free(s);
    for(i=0;i<n;i++){
        if(1>i)t=te[n-1]-te[i];
        else{
            t=te[n-1]-te[i];
            t+=tw[i-1];
        }
        if(m>t)m=t;
    }
    free(te);
    free(tw);
    printf("%d",m);
    return 0;
}

Measured memory_bytes: 2816
#include<stdio.h>
int main()
{
	int A,B,C,flag=0;
	scanf("%d %d %d",&A,&B,&C);
	1<=A<=10;
	1<=B<=10;
	1<=C<=10;
	if(A==5 && B==5 && C==7) flag=1;
	if(A==5 && B==7 && C==5) flag=1;
	if(A==7 && B==5 && C==5) flag=1;
		if(flag==1)
			printf("YES\n");
			else
				printf("NO\n");
	return 0;
}



Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;

int Emulate(int at, const string& s, const vector<int>& c, const vector<int>& d) {
  for (int i = 0; i < c.size(); ++i) {
    if (s[at] - 'A' != c[i]) continue;
    at += d[i];
    if (at < 0) return -1;
    if (at >= s.size()) return +1;
  }
  return 0;
}

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

  vector<vector<int>> pos(26);

  for (int i = 0; i < n; ++i) pos[s[i] - 'A'].push_back(i);

  vector<int> c(m), d(m);

  for (int i = 0 ; i < m; ++i) {
    char ch, type;
    cin >> ch >> type;
    c[i] = ch - 'A';
    d[i] = type == 'L' ? -1 : +1;
  }

  //cerr << endl;
  //for (int i = 0; i < n; ++i) cerr << Emulate(i, s, c, d) << endl;
  //cerr << endl;

  int result = 0;

  for (int letter = 0; letter < 26; ++letter) {
    if (pos[letter].empty()) continue;
    if (Emulate(pos[letter][0], s, c, d) != -1) continue;
    int l = 0;
    int r = pos[letter].size();
    while (r - l > 1) {
      int m = (l + r) / 2;
      if (Emulate(pos[letter][m], s, c, d) == -1) l = m; else r = m;
    }
    //cerr << char('A' + letter) << " to left: " << l + 1 << endl;
    result += l + 1;
  }

  for (int letter = 0; letter < 26; ++letter) {
    if (pos[letter].empty()) continue;
    if (Emulate(pos[letter].back(), s, c, d) != +1) continue;
    int l = -1;
    int r = pos[letter].size() - 1;
    while (r - l > 1) {
      int m = (l + r) / 2;
      if (Emulate(pos[letter][m], s, c, d) == +1) r = m; else l = m;
    }
    //cerr << char('A' + letter) << " to right: " << l + 1 << endl;
    result += pos[letter].size() - r;
  }

  cout << n - result << endl;
  return 0;
}


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;

using Graph = vector<vector<int>>;

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> d(n);
    for (int i = 0; i < n; i++)
    {
        cin >> d[i];
    }
    if (n == 1)
    {
        cout << abs(d[0] - x) << endl;
        return 0;
    }
    int ans = __gcd(abs(x - d[0]), abs(x - d[1]));
    for (int i = 0; i < n; i++)
    {
        ans = __gcd(ans, abs(x - d[i]));
    }
    cout << ans << endl;

    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);
    ll n,k,y,s=0;
    cin>>n>>k;
    ll w[n+1],a[n+2];
    for(ll i=0;i<n;i++){
        cin>>w[i]>>a[i];
        s+=a[i];
    }
    ll d[100010];
    for(ll j=1;j<100010;j++){
        d[j] = 1e9+7;
    }
    d[0]=0;
    for(ll i=0;i<n;i++){
        for(ll j=s;j>=a[i];j--){
            d[j] = min(d[j],d[j-a[i]]+w[i]);
        }
    }
    for(int i=0;i<=s;i++){
        if(k>=d[i]) y = i;
    }
    cout<<y;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  while(1){
    int a,b;
    cin>>a>>b;
    if(a==0 && b==0) break;
    if(a%2==1 && b%2==1) cout<<"no"<<endl;
    else cout<<"yes"<<endl;
  }
  return 0;
}



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

#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m);i>=(int)(n);--i)
#define debug(x) cout << #x << "=" << (x) << endl;

template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end
struct UnionFind{
  private:
  vector<int> par;
  int find(int k){
    if(par[k]<0)return k;
    else return (par[k]=find(par[k]));
  }
  public:
  UnionFind(int sz){
    par.assign(sz,-1);
  }
  bool same(int u,int v){
    return find(u)==find(v);
  }
  bool unite(int u,int v){
    u=find(u);v=find(v);
    if(u==v)return false;
    if(par[u]>par[v])swap(u,v);
    par[u]+=par[v];
    par[v]=u;
    return true;
  }
  int size(int k){return -par[k];}
};
void solve(){
  int n,q;
  cin>>n>>q;
  UnionFind uf(n);
  while(q-->0){
    int c,u,v;
    cin>>c>>u>>v;
    if(c==0)
      uf.unite(u,v);
    else cout<<(int)uf.same(u,v)<<endl;
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}



Measured memory_bytes: 3252
#import sys
#input = sys.stdin.readline
def main():
    k, x = map( int, input().split())
    ANS = []
    for i in range(1,k):
        ANS.append(x-k+i)
    ANS.append(x)
    for i in range(1,k):
        ANS.append(x+i)
    print(" ".join( map( str, ANS)))
if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int R,G,B,N;
  std::cin >> R >> G >> B >> N;

  int cnt = 0;
  int maxi = std::max({R,G,B});
  int mini = std::min({R,G,B});
  int mid = R+G+B - maxi - mini;
  rep(i,N/maxi+1){
    rep(j,N/mid+1){
      int a = N - maxi*i - mid*j;
      if(a < 0) break;
      else if(a%mini == 0) cnt++;
    }
  }

  std::cout << cnt << '\n';
  return 0;
}


Measured memory_bytes: 256
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll R=2e5+69, INF=2e9+6969, mod = 1e9+7;

ll n;

ll Pow(ll a, ll p)
{
	if(p == 0) return 1;
	if(p&1)
	{
		ll s = Pow(a,p-1);
		return (s*a)%mod;
	}
	else
	{
		ll s = Pow(a,p/2);
		return (s*s)%mod;
	}
}

int main()
{
	//  printf("%lld\n", Pow(10LL,100LL));
	scanf("%lld", &n);
	if(n == 1) puts("0");
	else
	{
		ll ans = Pow(10LL,n);
		ll bad = Pow(9LL,n)*2;
		bad -= Pow(8LL,n);
		bad %= mod;
		if(bad < 0) bad += mod;
		ans -= bad;
		if(ans < 0) ans += mod;
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 3836
import copy
s = list(input())
formula_list = []

def insert_(formula, count):
    global formula_list
    if len(formula) == 1:
        formula_list.append(formula)
        return 0
    no = copy.deepcopy(formula)
    yes = copy.deepcopy(formula)
    yes.insert(count, "+")

    count += 1

    if count < len(yes)-1:
        insert_(yes, count+1)
        insert_(no, count)
    else:
        formula_list.append(no)
        formula_list.append(yes)

def sum_list(for_list):
    s = 0
    for i in for_list:
        num = "".join(i)
        num = map(int, num.split("+"))
        s += sum(num)
    return s


insert_(s, 1)
print(sum_list(formula_list))


Measured memory_bytes: 41584
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000000



int main(){
	
	int A,B;
	cin>>A>>B;
	
	cout<<A*B<<endl;
	
	return 0;
}

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

#define vi vector<int>
#define vvi vector<vi>

int culmax(int &i,vi &dp,vvi &A){
  //更新済みの場合...そのまま返す
  if(dp.at(i)!=-1){return dp.at(i);}
  
  //未更新の場合...arcの先を更新しつつmaxを受け取る
  int result=0;
  for (int j : A.at(i)){
    result=max(result,culmax(j,dp,A)+1);
  }
  dp.at(i)=result;
  return result;
}

int main() {
  int N,M,ans=0; cin >> N >> M;
  vi dp(N,-1);
  vvi A(N,vi(0));
  for (int i=0;i<M;i++){
    int x,y; cin >> x >> y;
    A.at(x-1).push_back(y-1);
  }

  for (int i=0;i<N;i++){
    ans=max(ans,culmax(i,dp,A));
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 9472
#include <iostream>
#include <string>
#include <cstdio>
#include <iomanip>
using namespace std;


int main(){
    int N;
    cin >>N;
    double Y=0;
    for(int i=0;i<N;i++){
        double m;
        string syurui;
        cin >> m >> syurui;
        if(syurui=="JPY"){
            Y += m;
        }else{
            Y += m*380000.00000000;
        }
    }
    cout << fixed << setprecision(10) << Y <<endl;
}



Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
ll inf = 1000000000 + 7;

//bool operator< (pint a, pint b) {
	//return a.second < b.second;

//}



ll gcd(ll a, ll b) {

	if (b == 0)
		return a;

	return gcd(b, a % b);


}

ll max(ll a, ll b) {
	if (a < b) {
		return b;
	}
	else
		return a;

}

ll min(ll a, ll b) {
	if (a < b)
		return a;

	return b;
}




ll pow(ll a, ll b) {


	if (b == 0) return 1;

	if (a % 2 == 1) {
		a * pow(a, b - 1);
	}
	else {
		ll ret = pow(a, b / 2);
		return ret * ret;
	}
}






ll Col[505][505];
ll D[35][35];
ll num[3][35];

int main() {
	ll N, C;
	
	cin >> N >> C;


	rep(i, C) {
		rep(j, C) {
			cin >> D[i+1][j+1];
		}


	}


	rep(i, N) {
		rep(j, N) {

			cin >> Col[i][j];
			num[(i + j + 2) % 3][Col[i][j]] += 1;


		}


	}
	



	ll ans = inf;

	rep(i, C) {
		rep(j, C) {
			rep(k, C) {
				ll sum = 0;

				
					
				
			if(i != j && j != k && i != k) {
					rep(l, C) {

						sum += num[0][l + 1] * D[l + 1][i + 1] + num[1][l + 1] * D[l + 1][j + 1] + num[2][l + 1] * D[l + 1][k + 1];


					}

					ans = min(sum, ans);
				}


			}
		}

	}

	cout << ans << endl;
	


	
	return 0;
}

Measured memory_bytes: 2176
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            var rl = RL();
            //var sprlst = spr(rl);
            //var intlist = sprlst.Select(x => c2i(x)).ToList();
            var k = c2i(rl);
            //var ls1 = Enumerable.Range(0, 10).Select(x => (long)x);
            int[,] list = new int[k + 1, k + 1];
            Int64 ans = 0;
            for (int a = 1; a <= k; a++)
            {
                for (int b = 1; b <= k; b++)
                {
                    for (int c = 1; c <= k; c++)
                    {
                        var ls = new List<int> { a, b, c };
                        ls.Sort();
                        if (list[ls[0],ls[1]] == 0)
                        {
                            list[ls[0], ls[1]] = GetGCD(ls[0], ls[1]);
                        }
                        var ab=list[ls[0],ls[1]];
                        if (ab > ls[2]) { var tm = ab; ab = ls[2]; ls[2] = tm; }
                        if(list[ab,ls[2]]==0){
                            list[ab, ls[2]] = GetGCD(ab, ls[2]);
                        }
                        var gcd = list[ab, ls[2]];
                        //Console.WriteLine("a" + a + ",b" + b + ",c" + c + "ans" + gcd);
                        ans += gcd;
                    }
                }
            }







                Console.WriteLine(ans);
            Console.ReadLine();
        
        }
        static int GetGCD(int a, int b)
        {
            int tmp;
            if (a < b) { tmp = a; a = b; b = tmp; }
            if (b < 1) return -1;
            if (a % b == 0) return b;
            return GetGCD(b, a % b);
        }
        static string RL() { return Console.ReadLine().Trim(); }
        static IEnumerable<string> spr(string s) { return s.Split(' '); }
        static Int64 c2i(string c) { return Int64.Parse(c); }
        //static double c2d(string c) { return double.Parse(c); }
        static string bool2ret(bool b) { return b ? "Yes" : "No"; }
    }
}


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

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

    if(s == "Sunny")
        cout << "Cloudy\n";
    if(s == "Cloudy")
        cout << "Rainy\n";
    if(s == "Rainy")
        cout << "Sunny\n";

    return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>

int main(){
	int a,b,t;
	
	while(0<=scanf("%d%d",&a,&b)){
		if(a<b){
			t=a;
			a=b;
			b=t;
		}
		while(a%b!=0){
			a=a%b;
			if(a<b){
				t=a;
				a=b;
				b=t;
			}
//			printf("%d %d\n",a,b);
		}
		
		printf("%d\n",b);
	}
	return 0;
}

Measured memory_bytes: 0
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

void Init() {
	std::cin.tie(0); std::ios::sync_with_stdio(false);
	struct Init_caller { Init_caller() { Init(); } }caller;
}

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define ei else if
#define all(a) a.begin(),a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define int_INF 1<<29
#define ll_INF 1LL<<60
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using ppi = pair<pi, LL>;
using mll = map<LL, LL>;
using mcl = map<char, LL>;
using vpi = vector<pi>;
using vppi = vector<ppi>;

#pragma endregion

void y_n(bool p) {
	p ? _y() : _n();
}

void Y_N(bool p) {
	p ? _Y() : _N();
}

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

//素数判定
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		ret %= MOD;
	}
	return ret;
}

#pragma endregion 


/*****************************************************************************/
int nmax = 40, abmax = 10;

signed main(void) {
	int n, ma, mb;
	cin >> n >> ma >> mb;
	vi a(nmax), b(nmax), c(nmax);
	vvvi dp(nmax + 1, vvi(nmax*abmax + 1, vi(nmax*abmax + 1, ll_INF)));
	f_v3I(a, b, c, n);
	dp[0][0][0] = 0;
	f(i, 0, n) {
		f(ca, 0, nmax*abmax + 1) {
			f(cb, 0, nmax*abmax + 1) {
				if (dp[i][ca][cb] == ll_INF)continue;
				dp[i + 1][ca][cb] = min(dp[i + 1][ca][cb], dp[i][ca][cb]);
				dp[i + 1][ca + a[i]][cb + b[i]] = min(dp[i + 1][ca + a[i]][cb + b[i]], dp[i][ca][cb] + c[i]);
			}
		}
	}
	int ans = ll_INF;
	f(ca, 1, nmax*abmax + 1) {
		f(cb, 1, nmax*abmax + 1) {
			if (ca*mb == cb * ma) {
				ans = min(ans, dp[n][ca][cb]);
			}
		}
	}
	if (ans == ll_INF) {
		cout << -1;
	}
	else {
		cout << ans;
	}
	return 0;
}

Measured memory_bytes: 53504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 998244353;
int cs[1000], ma[1000];
int main()
{
	int h, w;
	cin >> h >> w;
	int n;
	cin >> n;
	int sh, sw;
	cin >> sh >> sw;
	ma['R'] = w - sw + 1, ma['L'] = sw, ma['D'] = h - sh + 1, ma['U'] = sh;
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < (int)s.length(); ++i)
	{
		cs[(int)s[i]]++;
		if (cs[(int)s[i]] == ma[(int)s[i]])
		{
			//cout << i << endl;
			cout << "NO" << endl;
			return 0;
		}
		if (t[i] == 'R')
		{
			cs['L']--;
			cs['L'] = max(-ma['R'] + 1, cs['L']);
		}
		if (t[i] == 'L')
		{
			cs['R']--;
			cs['R'] = max(-ma['L'] + 1, cs['R']);
		}
		if (t[i] == 'D')
		{
			cs['U']--;
			cs['U'] = max(-ma['D'] + 1, cs['U']);
		}
		if (t[i] == 'U')
		{
			cs['D']--;
			cs['D'] = max(-ma['U'] + 1, cs['D']);
		}
	}
	cout << "YES" << endl;
}

Measured memory_bytes: 776
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cctype>

using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)

int main() {
    string S;
    getline(cin, S);

    string str;
    rep(i, S.size()) {
        if (islower(S[i]))str+=toupper(S[i]);
        else if (isupper(S[i]))str+=tolower(S[i]);
        else str += S[i];
    }
    cout << str << endl;
}


Measured memory_bytes: 3232
/*siddharth goyal*/
#include<bits/stdc++.h>
using namespace std;
#define   pb              push_back
#define   REP(i,n)        for(int i=1;i<=n;i++)
#define   FOR(i,a,b)      for(int i=a;i<=b;i++)
#define   all(v)          v.begin(),v.end()
#define   F               first
#define   S               second
#define   vl              vector<LL>
#define   itr             ::iterator it
#define   lb              lower_bound
#define   ub              upper_bound
#define   LL              long long
#define   ULL             unsigned long long
#define   ret             return 
#define   sz(x)           (LL)x.size()
LL n,i,j,ans = 0;
LL a[1000000],dp[500][500],b[500];
LL f(LL start,LL end)
{  if(dp[start][end]!=-1)  ret dp[start][end] ; 
   dp[start][end] = (LL)1E18 ;
   if(end>n) ret 0 ; 
   if(start==end)
   {  //b[start][end] = a[start] ;  
      ret dp[start][end] = 0 ; 
   } 
   for(int i=start;i<end;i++)
   {  if(dp[start][end]>f(start,i) + f(i+1,end) - b[start-1] + b[end])
        dp[start][end] = min(dp[start][end],dp[start][i] + dp[i+1][end]  - b[start-1] + b[end]) ;
         //b[start][end] = b[start][i] + b[i+1][end] ;     
      
          
   }
   ret dp[start][end] ; 
} 
int main()
{   // Read the constraints,highlights,Time Limit,Test Cases
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n ; 
    REP(i,n) cin>>a[i] ;
    partial_sum(a+1,a+1+n,b+1) ;
    memset(dp,-1,sizeof(dp)) ; 
    f(1,n) ; 
    cout<<dp[1][n]<<endl; 
}
//Check for 0,1 and other corner cases.

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法
#define JUUHATI 1000000000000000000 
#define JUUHATIPLUS 1000000000000000001 

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

//精度系の問題はprintfを使うべき

int main(){
    double ans;
    int L;
    cin >> L;
    ans = (double)L * L * L / 27;

    printf("%.12f",ans);
    cout << endl;


    

}

Measured memory_bytes: 3748
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#define MOD 1000000007LL
using namespace std;

int main(){
	string s, t;
	cin >> s >> t;
	char a[s.size()], b[t.size()];
	for(int i = 0; i < s.size(); i++) a[i] = s[i];
	for(int i = 0; i < t.size(); i++) b[i] = t[i];
	sort(a, a+s.size());
	sort(b, b+t.size());
	reverse(b, b+t.size());
	if(lexicographical_compare(a, a+s.size(), b, b+t.size())) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>

using namespace std;

const int SIZE = 13;

struct Puzzle{
  short c[SIZE];
  
  void move(int d, int n){
    if(d == 0) moveUp(n);
    if(d == 1) moveDown(n);
    if(d == 2) moveLeft(n);
    if(d == 3) moveRight(n);
  }
  // n = choosed blank number 0(first one) or 1(second one)
  void moveUp(int n){
    int pos = findBlankPosition(n);
    int tmp[] = {-1,-1,0,-1,-1,1,2,3,-1,5,6,7,10};
     
    int npos = tmp[pos];
    if(npos != -1) swap(c[pos],c[npos]);
  }
  
  void moveDown(int n){
    int pos = findBlankPosition(n);
    int tmp[] = {2,5,6,7,-1,9,10,11,-1,-1,12,-1,-1};
    
    int npos = tmp[pos];
    if(npos != -1) swap(c[pos],c[npos]);
  }
  
  void moveLeft(int n){
    int pos = findBlankPosition(n);
    int tmp[] = {-1,-1,1,2,-1,4,5,6,7,-1,9,10,-1};
    
    int npos = tmp[pos];
    if(npos != -1) swap(c[pos],c[npos]);
  }
  
  void moveRight(int n){
    int pos = findBlankPosition(n);
    int tmp[] = {-1,2,3,-1,5,6,7,8,-1,10,11,-1,-1};
     
    int npos = tmp[pos];
    if(npos != -1) swap(c[pos],c[npos]);
  }
  
  int findBlankPosition(int n){
    for(int i = 0; i < SIZE; i++){
      if(c[i] == 0) n--;
      if(n < 0) return i;
    }
    return -1;
  }
  
  bool operator < (const Puzzle& p) const {
    for(int i = 0; i < SIZE; i++)
      if(c[i] != p.c[i]) return c[i] < p.c[i];
    return false;
  }
  
  bool operator == (const Puzzle& p) const {
    for(int i = 0; i < SIZE; i++)
      if(c[i] != p.c[i]) return false;
    return true;
  }
};

Puzzle puz;
 
bool input(){
  cin >> puz.c[0];
  if(puz.c[0] == -1) return false;
  for(int i = 1; i < SIZE; i++) cin >> puz.c[i];
  return true;
}
 
void solve(){
  map<Puzzle, int> M;
  M[puz] = 1;
  
  Puzzle ans_case;
  for(int i = 0; i < SIZE; i++) ans_case.c[i] = i%(SIZE-1);

  queue<Puzzle> Q;
  Q.push(puz);

  while(!Q.empty()){
    Puzzle now = Q.front(); Q.pop();
    if(now == ans_case){
      cout << M[now]-1 << endl;
      return;
    }
    for(int i = 0; i < 4; i++)
      for(int j = 0; j < 2; j++){
	Puzzle nex = now;
	nex.move(i,j);
	if(M[nex] > M[now]+1|| M[nex] == 0){
	  M[nex] = M[now]+1;
	  if(M[nex] < 11) Q.push(nex);
	}
      }
  }
 
  
  Puzzle tmp = ans_case;
  Q.push(tmp);
  map<Puzzle,int> MG;
  MG[tmp] = 1;
 
  while(!Q.empty()){
    Puzzle now = Q.front(); Q.pop();
    if(M[now] != 0){
      cout << M[now]+MG[now]-2 << endl;
      return;
    }

    for(int i = 0; i < 4; i++)
      for(int j = 0; j < 2; j++){
	Puzzle nex = now;
	nex.move(i,j);
	
        if(MG[nex] > MG[now]+1 || MG[nex] == 0){
	  MG[nex] = MG[now]+1;
	  if(MG[nex] <= 11) Q.push(nex);
	}
      }
  }
  cout << "NA" << endl;
}
 
int main(){
  while(input()) solve();
  return 0;
}

Measured memory_bytes: 5124
#include <bits/stdc++.h>
using namespace std;
bool solve(int N)
{
	int n=N;
	for(int i=n;i>=0;i-=7)
	{
		if(i%4==0)return true;
	}
	return false;
}
int main()
{
	int N;
	cin>>N;
	if(solve(N)){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    string S;
    cin >> S;
    int N = S.size();
    int res = 0;
    char s = S[0];
    FOR(i, 1, N, 1) {
        if (s != S[i]) {
            res++;
            s = S[i];
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int ll;
typedef vector<int > vecint;
typedef vector<bool > vecbool;
typedef vector<string > vecstr;
int n, m, k;
vector<unordered_set<int>> fr;
vector<unordered_set<int>> nonfr;
vector<unordered_set<int>> tree;
vecbool seen;
vecint tmap;
void dfs(int i, int x){
  //loop for friend x
  if(!seen[x]){
    seen[x] = true;
    tree[i].insert(x);
    tmap[x] = i;
  }
  for(auto itr = fr[x].begin(); itr!= fr[x].end();itr++){
    if(seen[*itr])continue;
    seen[*itr] = true;
    tree[i].insert(*itr);
    tmap[*itr] = i;
    dfs(i, *itr);
  }
}
int main()
{
  cin >> n >> m >> k;
  ///////
  fr.resize(n + 1);
  nonfr.resize(n + 1);
  int a, b;
  REP(i,m){
    cin >> a >> b;
    fr[a].insert(b);
    fr[b].insert(a);
    nonfr[a].insert(b);
    nonfr[b].insert(a);
  }
  REP(i,k){
    cin >> a >> b;
    nonfr[a].insert(b);
    nonfr[b].insert(a);
  }
  ///////
  seen.resize(n + 1);
  fill(all(seen), false);
  seen[0] = true;
  tmap.resize(n + 1);
  fill(all(tmap), -1);
  ///////
  int ini = 1;
  int nt = 0;
  bool ok = false;
  while(!ok){
    tree.push_back(unordered_set<int >());
    dfs(nt,ini);
    nt++;
    ok = true;
    for(int i = ini; i <= n; i++){
      if(!seen[i]){
	ini = i;
	ok = false;
	break;
      }
    }
  }
  // for(int i = 0; i < tree.size(); i ++){
  //   cout << "tree "<<i << endl;
  //   for(auto itr = tree[i].begin(); itr != tree[i].end();itr++){
  //     cout << *itr << " ";
  //   }
  //   cout << endl;
  // }
  // for(int i = 1; i < fr.size(); i ++){
  //   cout << "fr "<<i << endl;
  //   for(auto itr = fr[i].begin(); itr != fr[i].end();itr++){
  //     cout << *itr << " ";
  //   }
  //   cout << endl;
  // }
  // for(int i = 1; i < nonfr.size(); i ++){
  //   cout << "nonfr "<<i << endl;
  //   for(auto itr = nonfr[i].begin(); itr != nonfr[i].end();itr++){
  //     cout << *itr << " ";
  //   }
  //   cout << endl;
  // }
  // vecint num(nt + 1,0);
  // for(int i = 1; i <= n; i++){
  //   num[tmap[i]]++;
  // }
  for(int i = 1; i <= n; i ++){
    // cout << tmap[i] << endl;
    int ans = 0;
    for(auto itr = nonfr[i].begin(); itr != nonfr[i].end(); itr++){
      if(tree[tmap[i]].find(*itr)!= tree[tmap[i]].end()) ans ++;
    }
    ans = tree[tmap[i]].size() - ans - 1;
    // ans = num[tmap[i]] - nonfr[i].size() - 1;
    cout << ans <<" ";
  }
  cout << endl;
}


Measured memory_bytes: 49744
#define ll				long long
#define MOD				1000000007

#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

FILE *in, *ans;
int tno;

int out(const char *s) {
#ifdef TEST
	char buf[8192];
	fgets(buf, sizeof(buf), ans);
	if (strcmp(buf, s)) {
		printf("err\n");
	}
#else
	printf(s);
#endif
	return 0;
}

int outi(int i) {
	char s[128];
	sprintf(s, "%d\n", i);
	out(s);
	return 0;
}

int outd(double d) {
	char s[128];
	sprintf(s, "%.10lf\n", d);
	out(s);
	return 0;
}

int outll(ll l) {
	char s[128];
	sprintf(s, "%lld\n", l);
	out(s);
	return 0;
}

int geti() {
	int i;
	fscanf(in, "%d", &i);
	return i;
}

ll getll() {
	ll l;
	fscanf(in, "%lld", &l);
	return l;
}

int getstr(char *s) {
	fscanf(in, "%s", s);
	return 0;
}

int getmin(int val1, int val2) {
	if (val1 < val2) {
		return val1;
	}
	else {
		return val2;
	}
}

int getmax(int val1, int val2) {
	if (val1 > val2) {
		return val1;
	}
	else {
		return val2;
	}
}

typedef struct data {
	char c;
	int cnt;
} data;

int a[100005];
int n, m;

int fnc2() {
	int i;
	int n = geti();
	int m = geti();
	for (i = 0; i < m; i++) {
		int no = geti();
		a[no] = -1;
	}

	a[0] = 1;
	for (i = 0; i < n; i++) {
		if (a[i] > 0) {
			if (a[i + 1] >= 0) {
				a[i + 1] += a[i];
				a[i + 1] %= MOD;
			}
			if (a[i + 2] >= 0) {
				a[i + 2] += a[i];
			}
		}
	}

	return a[n];
}

int fnc1() {
	int ret = fnc2();
	outi(ret);
	return 0;
}

int main() {

#ifdef TEST
	for (tno = TEST_SNO; tno <= TEST_ENO; tno++) {
		char str[128];
		sprintf(str, "test%d.txt", tno);
		in = fopen(str, "r");
		sprintf(str, "ans%d.txt", tno);
		ans = fopen(str, "r");
		fnc1();
		fclose(in);
		fclose(ans);
	}
	printf("end\n");
#else
	in = stdin;
	fnc1();
#endif

	return 0;
}


Measured memory_bytes: 512
N = int(input())
S = input()

r , g, b = S.count("R"), S.count("G"), S.count("B")
ans = r * g * b

for i in range(N-2):
    for d in range(1,N//2+1):
        j = i + d
        k = j + d
        if k >= N:break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ans -= 1
print(ans)

Measured memory_bytes: 9080
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 9e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class BUnhappyHackingABCEdit {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    string s;
	    in >> s;
	    string res = "";

	    for(int i=0; i<s.length(); i++){
	        if(s[i] == '1') res += '1';
	        else if(s[i] == '0') res += '0';
	        else{
	            if(res.length() > 0){
	                res = res.substr(0, res.length()-1);
	            }
	        }
	    }

	    out << res << endl;
	}
};


int main() {
	BUnhappyHackingABCEdit solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long 
using namespace std;
const int maxn = 2e5 + 7;
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
    int s, w;
    cin >> s >> w;
    if(s <= w) cout << "unsafe";
    else cout << "safe";
}

Measured memory_bytes: 3644
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Map<Long, Boolean> map = new HashMap<>();
    for(int i = 0; i < n; i++){
      long tmp = sc.nextLong();
      if(!map.containsKey(tmp)){
        map.put(tmp, false);
      }
      map.put(tmp, !map.get(tmp));
    }
    int count = 0;
    for(boolean flag : map.values()){
      if(flag){
        count++;
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 67732
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int N, M;
    cin >> N >> M;
    int left = 1, right = N;
    rep(i, M) {
        int l, r;
        cin >> l >> r;
        left = max(left, l);
        right = min(right, r);
    }
    int ans = max(0, right - left + 1);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3648
def solve(n, m, LR):
    maxl = 0
    minr = n
    for l, r in LR:
        if maxl < l:
            maxl = l
        if minr > r:
            minr = r
    return minr - maxl + 1 if maxl <= minr else 0

_n, _m = map(int, input().split())
_LR = [list(map(int, input().split())) for _ in range(_m)]
print(solve(_n, _m, _LR))


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

int main() {
  int n;
  cin >> n;
  vector<string> a(n);
  rep(i,n) cin >> a.at(i);
  int m;
  cin >> m;
  vector<string> b(m);
  rep(i,m) cin >> b.at(i);

  int ans = 0;
  rep(i,n){
    int cnt = 0;
    rep(j,n){
      if(a.at(i) == a.at(j)) cnt++;
    }
    rep(j,m){
      if(a.at(i) == b.at(j)) cnt--;
    }
    ans = max(ans,cnt);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,ans;
    cin >> n;
    string s1,s2;
    cin >> s1>>s2;
    vector<int> info={};
    for(int i =0;i<n;i++){
        if(s1[i] == s2[i]){
            info.push_back(1);
            continue;
        }
        if(s1[i] == s1[i+1]){
            info.push_back(2);
            i++;
            continue;
        }
    }

    long long dp[info.size()+10];
    if(info[0] == 1){
        ans = 3; 
    }else if(info[0] == 2){
        ans = 6;
    }

    for(int i= 1;i<info.size();i++){
        if(info[i] == 1){
            if(info[i-1] == 1){
                ans = ans*2;
                ans = ans%1000000007;
            }
        }else if(info[i] == 2){
            if(info[i-1] == 1){
                ans = ans*2;
                ans = ans%1000000007;
            }else if(info[i-1] == 2){
                ans = ans*3;
                ans = ans%1000000007;
            }
        }
    }



    cout << ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,j,a,b,c,d;
	scanf("%d/%d/%d",&a,&b,&c);
	d=a*10000+b*100+c;
	if(d<=20190430) cout<<"Heisei";
	else
	cout<<"TBD";
}

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

int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	set<int> s[2];
	for(int i = 0; i < m; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		if(a == 1) s[0].insert(b);
		if(b == 1) s[0].insert(a);
		if(a == n) s[1].insert(b);
		if(b == n) s[1].insert(a);
	}
	for(auto to: s[0]) {
		if(s[1].count(to)) {
			printf("POSSIBLE\n");
			return 0;
		}
	}
	printf("IMPOSSIBLE\n");
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int INF = 1000000007;

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

  int a, b, c;
  cin >> a >> b >> c;
  cout << a + b + c - max({a, b, c}) << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 xdddddddddddddddddd
#define y1 ydddddddddddddddddd

int n,a[100005],x,y,t;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        x=max(x,a[i]);
    }
    t=INF;
    for(int i=1;i<=n;i++){
        if(a[i]==x) continue;
        if(abs(x-2*a[i])<t) t=abs(x-2*a[i]),y=a[i];
    }
    cout << x << ' ' << y;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 1000000000000000000ll
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}

// string to integer stuuu()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

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

#define S second
#define F first
#define int long long  
///////

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int n;
	cin>>n;
	pair<string,pair<int,int>> p[n];
	for(int i=0;i<n;++i)
	{
		cin>>p[i].F>>p[i].S.F;
		p[i].S.F=-p[i].S.F;
		p[i].S.S=i+1;
	}
	sort(p,p+n);
	for(int i=0;i<n;++i)
	{
		cout<<p[i].S.S<<"\n";
	}
}

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

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

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


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

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

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

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

    return arr


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


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

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

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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

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

    divisors.sort()
    return divisors


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

m,d = lr()
ans = 0
for i in range(1,m+1):
    for j in range(10,d+1):
        if i == (j%10)*(j//10) and j%10>=2 and j//10>=2:
            ans+=1
print(ans)

Measured memory_bytes: 77480
lines = STDIN.read.strip.lines.map(&:strip)
arr = lines.last.split(' ').map(&:to_i)

curr = 1
cnt = 0
arr.size.times do |i|
    if arr[i] == curr
        curr += 1
    else
        arr[i] = 0
        cnt += 1
    end
end
arr = arr.reject(&:zero?)
if arr.size == arr.last
    puts cnt
else
    puts -1
end

Measured memory_bytes: 18832
it = lambda: list(map(int, input().strip().split()))


def count(num):
    cnt = 0
    while num > 0:
        if num & 1:
            cnt += 1
        num = num >> 1
    return cnt

def find(num):
    ans = 0
    while num > 0:
        ans += 1
        cnt = count(num)
        num = num % cnt
    return ans

def create(N, cnt):
    cur = 1
    two = [0] * N
    for i in range(N):
        two[i] = cur % cnt
        cur = (cur << 1) % cnt
    return two

def getRem(N, A, cnt, two):
    rem = 0
    for i in range(N):
        if A[i] == '1':
            rem = (rem + two[N - i - 1]) % cnt
    return rem

def solve():
    N = int(input())
    A = list(input().strip())

    popcount = 0
    for i in range(N):
        if A[i] == '1':
            popcount += 1
    
    more = popcount + 1
    less = popcount - 1

    if less != 0:
        less_two = create(N, less)
        rem_less = getRem(N, A, less, less_two)
    more_two = create(N, more)
    rem_more = getRem(N, A, more, more_two)
    
    nums = []
    for i in range(N):
        if A[i] == '1':
            if less == 0:
                nums.append(-1)
            else:
                nums.append((rem_less - less_two[N - i - 1]) % less)
        else:
            nums.append((rem_more + more_two[N - i - 1]) % more)
    # print(nums)

    for num in nums:
        if num == -1:
            print(0)
        else:
            print(find(num) + 1)


solve()

Measured memory_bytes: 34748
n = io.read("*n", "*l")
t = {}
for i = 1, n do
  s = io.read()
  name, p = s:match("(%w+) (%d+)")
  t[i] = {name, tonumber(p), i}
end
table.sort(t, function(a, b)
  if a[1] ~= b[1] then
    return a[1] < b[1]
  else
    return a[2] > b[2]
  end
end)
for i = 1, n do
  print(t[i][3])
end


Measured memory_bytes: 888
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
using System.Numerics;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";

    int N;
    long A, B, C, D;
    void Solve()
    {
        N = cin.Nextint;
        A = cin.Nextlong;
        B = cin.Nextlong;
        C = cin.Nextlong;
        D = cin.Nextlong;


        long ue1 = A + D;
        long sita1 = A + C;

        long ue2 = A - C;
        long sita2 = A - D;

        for (int i = 2; i < N; i++)
        {
            if ((ue1 + sita1) / 2 > B)
            {
                ue1 -= C;
                sita1 -= D;
            }
            else
            {
                ue1 += D;
                sita1 += C;
            }
            if ((ue2 + sita2) / 2 > B)
            {
                ue2 -= C;
                sita2 -= D;
            }
            else
            {
                ue2 += D;
                sita2 += C;
            }
        }

        //WriteLine($"{ue1} {sita1} {ue2} {sita2}");
        if ((sita1 <= B && B <= ue1) || (sita2 <= B && B <= ue2))
        {
            WriteLine("YES");
        }
        else
        {
            WriteLine("NO");
        }

    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

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

int main() {
    int h, w, d;
    cin >> h >> w >> d;
    map<int, pair<int, int>> mp;
    rep(i, h) rep(j, w) {
        int tmp_a;
        cin >> tmp_a;
        mp[tmp_a] = make_pair(i, j);
    }
    int q;
    cin >> q;
    vector<int> lv(q);
    vector<int> rv(q);
    rep(i, q) cin >> lv[i] >> rv[i];
    vector<vector<int>> modsum(d, vector<int>(h*w/d+10));
    int i = 0;
    while(1) {
        if ( i == d ) break;
        int j = 0;
        int tmp_p = i;
        while(1) {
            if ( tmp_p + d > h * w ) break;
            if ( j < 1 ) {
                modsum[i][j] = (abs(mp[tmp_p+d].first - mp[tmp_p].first) + abs(mp[tmp_p+d].second - mp[tmp_p].second));
            }
            else {
                modsum[i][j] = (modsum[i][j-1] + abs(mp[tmp_p+d].first - mp[tmp_p].first) + abs(mp[tmp_p+d].second - mp[tmp_p].second));
            }
            tmp_p += d;
            ++j;
        }
        ++i;
    }
//    rep(i, d) {
//        for ( auto tmp_modsum : modsum[i] ) {
//            printf("%d ", tmp_modsum);
//        } 
//        printf("\n");
//    }
    i = 0;
    while(1) {
        if ( i == q ) break;
        int ans = 0;
        int mod_p = lv[i] % d;
        int start_p = lv[i] / d;
        int end_p = rv[i] / d;
        if ( start_p < 1 ) cout << modsum[mod_p][end_p-1] << endl;
        else               cout << modsum[mod_p][end_p-1] - modsum[mod_p][start_p - 1] << endl;
        ++i;
    }
    return 0;
}


Measured memory_bytes: 14592