akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N;
	cin >> N;
	int A[100000];
	rep(i, N) cin >> A[i];

	int k = 0;
	vector<int> V, V2;
	V.pb(0);
	rep(i, N) {
		if (A[i] > k) {
			V.pb(A[i]);
			V2.pb(i);
			k = A[i];
		}
	}
	ll B[100001] = {};
	int C[100001] = {};
	rep(i, N) {
		int k2 = lower_bound(V.begin(), V.end(), A[i]) - V.begin();
		B[k2] += A[i] - V[k2 - 1];
		C[k2]++;
	}

	int mae = V.back();
	ll l = C[(int)V.size()];
	ll kotae[100001] = {};
	for (int k = (int)V.size() - 2; k >= 0; k--) {
		kotae[V2[k]] = B[k + 1] + l * (mae - V[k]);
		mae = V[k];
		l += C[k + 1];
	}

	rep(i, N) co(kotae[i]);

	Would you please return 0;
}

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

int main() {
long long h,w;
cin>>h>>w;
char a[h+1][w+1];
for(int i=1;i<h+1;i++)
{
	for(int j=1;j<w+1;j++)
	cin>>a[i][j];
	
}

long long n[h+1][w+1];
n[1][1]=1;
for(int i=2;i<h+1;i++)
{
	if(a[i-1][1] == '.')
	n[i][1]=n[i-1][1];

	else n[i][1]=0;
	
}
for(int i=2;i<w+1;i++)
{
	if(a[1][i-1] == '.')
	n[1][i]=n[1][i-1];

	else n[1][i]=0;

}

for(int i=2;i<h+1;i++)
{
	for(int j=2;j<w+1;j++)
	{
		if(a[i-1][j] == '.' && a[i][j-1] == '.')
		n[i][j]= n[i-1][j] + n[i][j-1];

		else if(a[i-1][j] == '.' && a[i][j-1] == '#')
		n[i][j]= n[i-1][j];

		else if(a[i-1][j] == '#' && a[i][j-1] == '.')
		n[i][j]= n[i][j-1];

		else 	n[i][j]= 0;
		
		if(n[i][j] !=0)
		n[i][j]=n[i][j]%1000000007;

	}
}
	cout<<n[h][w];
	// your code goes here
	return 0;
}

Measured memory_bytes: 9088
#include<iostream>
#include<string>
#include<algorithm>
#include <sstream>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include <vector>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;
#include <unordered_map>
const int mod = 1e9+7;
int a[100][100];
int main()
{
    int n;
    string s;
    vector<string>res;
    cin>>n;

    for(int i=0;i<n;i++)
    {
        cin>>s;
        res.push_back(s);
    }

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<res[i].size();j++)
        {
            a[i][res[i][j]-'a']++;
        }
    }
    s.clear();
    for(int i=0;i<26;i++)
    {
        int t = 1e9;
        for(int j=0;j<n;j++)
        {
            t =min(t,a[j][i]);
        }

        for(int j=0;j<t;j++)
        {
            s+=i+'a';
        }
    }
    cout<<s<<endl;
    return 0;
}


/*
4 4
1 3 4 5
2 4 5 6
1  2

2 3 4 1 2 1 sx

2 3 4 1 2 1 sy

2*sy+ 3*sy + 4*sy+ ...1*sy

(x2-x1 + x3- x1+x4-x1+x3-x2+x4-x2+x5-x2+x4-x3+x5-x3+x5-x4)

(3*(-x1)+(0)*x1+ (2)*(-x2)+(1)*x2 )
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 305
#define inf 2e9
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define mm 1000000007
#define pii pair<int,int> 
#define ll long long
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define low(x) x&(-x)
#define for_each(iter,container) for(typeof(container.begin()) iter=container.begin();iter!=container.end();++iter)
using namespace std;
ll read(){
	ll x=0,f=1; char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1; ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
struct data{int obj,pre,c;}e[maxn*maxn];
int vis[maxn],gg[maxn][maxn],head[maxn];
ll a[maxn][maxn],c[maxn][maxn],ans;
int n,tot,sum;
void insert(int x,int y,ll c){
	e[++tot].obj=y; e[tot].pre=head[x]; e[tot].c=c;head[x]=tot;
}
void dfs(int u){
	vis[u]=1; sum++;
	for (int j=head[u];j;j=e[j].pre){
		int v=e[j].obj;
		if (!vis[v]) dfs(v);
	}
}
int main() {
	n=read();
	rep(i,1,n) rep(j,1,n) a[i][j]=read();
	rep(k,1,n) {
		rep(i,1,n) rep(j,1,n) if (i!=j&&i!=k&&j!=k&&a[i][k]+a[k][j]==a[i][j]) gg[i][j]=1;
	}
	rep(i,1,n) rep(j,1,n) if (i==j) c[i][j]=0; else c[i][j]=inf;
	rep(i,1,n) rep(j,i+1,n) 
		if (!gg[i][j]) insert(i,j,a[i][j]),insert(j,i,a[i][j]),ans+=a[i][j],c[i][j]=c[j][i]=a[i][j];
	dfs(1);
//	printf("%lld\n",ans);
	if (sum!=n) {puts("-1"); return 0;}
	rep(k,1,n) rep(i,1,n) rep(j,1,n) c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
	rep(i,1,n) rep(j,1,n) if (c[i][j]!=a[i][j]) {puts("-1"); return 0;}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2688
def main():  
  import sys
  input = sys.stdin.readline
  n = int(input())
  a = [int(i) for i in input().split()]
  b = [int(i) for i in range(n)]
  ab = [(x,y) for x,y in zip(a,b)]
  from operator import itemgetter
  ab = sorted(ab,key=itemgetter(0),reverse=True)
  dp = [[-10**14]*(n+1) for i in range(n+1)]
  dp[0][0] = 0
  for i in range(n):
    for j in range(i+2):
      if j >= 1:
        dp[i+1][j] = max(dp[i][j]+ab[i][0]*abs(ab[i][1]-(n-1-(i-j))),dp[i][j-1]+ab[i][0]*abs(ab[i][1]+1-j))
      if j == 0:
        dp[i+1][0] = dp[i][0] + ab[i][0]*abs(ab[i][1]-(n-1-i))
  print(max(dp[n]))
if __name__ == '__main__':
    main()

Measured memory_bytes: 136220
/*include*/
	#include <stdio.h>
	#include <stdlib.h>
	#include <math.h>
	#include <time.h>
	#include <assert.h>
	#include <ctype.h>
	#include <locale.h>
	#include <setjmp.h>
	#include <string.h>
	#include <signal.h>
	#include <limits.h>
	#include <stdarg.h>
	#include <stdbool.h>

/*typedef */
	typedef long long ll;
	typedef char  string[1000];
	
/*define*/

	/*scan*/
		#define scan_d(a) scanf("%d",&a);
		#define scan_c(a) scanf("%c",&a), getchar();
		#define scan_f(a) scanf("%f",&a);
		#define scan_s(a) scanf("%s",a);

	/*define funcs*/
		#define sort_d(array,size)	qsort(array,size,sizeof(int),intcmp)  
		#define sort_c(array,size)	qsort(array,size,sizeof(char),charcmp)  
		#define rand_range(min,max) (min)+(rand())%((max)-(min)+(1))
		#define rep(i,j) for(int i=0;i<j;i++)

/*functions in funcs.h*/
	int intcmp(const void *a,const void *b);
	int charcmp(const void *a,const void *b);
	bool is_sorted(int *start,int *end);


/*main program*/
int main(void)
{
	int d;
	scan_d(d);
	printf("%d\n",(int)pow(d,3));
}

Measured memory_bytes: 256
def b():
    import re
    s = input()
    s = re.sub(r'BC', 'D', s)
    ls = range(len(s))
    ac, c = 0, 0
    for i in ls:
        if s[i] == 'A':
            ac += 1
        elif s[i] == 'D':
            c += ac
        else:
            ac = 0
    return c


ans = b()
print(ans)

Measured memory_bytes: 46688
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;

  lll n,a,b;

  cin >> n >> a >> b;

  lll sum;
  lll mod;
  
  sum = n/(a+b) *a;
  mod = n % (a+b);

  if(mod >= a){
    sum += a;
  }
  else{
    sum += mod;
  }

  cout << sum;
  
  
  return 0;
}


Measured memory_bytes: 3636
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0),cin.sync_with_stdio(0),cout.tie(0),cout.sync_with_stdio(0);
	int a, b, c;
	cin>>a>>b>>c;
	c=max(0,c-(a-b));
	cout<<c;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
using namespace std;

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


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

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

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    string N;
    cin >> N;
    ll sum = 0;
    REP(i,N.size()){
        sum += N[i] - '0';
        sum %= 9;
    }
    cout << (sum == 0 ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

void primeFactorization(ll n, map<ll, ll>& result)
{
	for (auto i = 2ll; i * i <= n; ++i)
	{
		while (n % i == 0)
		{
			++result[i];
			n /= i;
		}
	}

	if (n != 1)
	{
		result[n] = 1;
	}
}

int main()
{
	ll A, B;
	cin >> A >> B;

	map<ll, ll> pA;
	map<ll, ll> pB;
	primeFactorization(A, pA);
	primeFactorization(B, pB);

	auto ans = 1ll;
	for (auto kv : pB)
	{
		if (pA.find(kv.first) != pA.end())
		{
			++ans;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  string t, s;std::cin >> s;
  //SS

  char end='&';
  char pre = 'S';
  t = "S";
  re(i, s.size()){
    int k = (s[i]=='o'?1:-1);
    if(t[i]=='W') k*=-1;
    int b = ((i==0?pre:t[i-1])=='S'?1:-1);
    if(k==-1) b*=-1;
    if(b==1){
      if(i==s.size()-1){
        end = 'S';
        break;
      }
      t+='S';
    }else {
      if(i==s.size()-1){
        end = 'W';
        break;
      }
      t+='W';
    }
  }
  if(pre==t[n-1]&&t[0]==end){
    std::cout << t << '\n';
    return 0;
  }
  //SW
  pre = 'S';
  t = "W";
  re(i, s.size()){
    int k = (s[i]=='o'?1:-1);
    if(t[i]=='W') k*=-1;
    int b = ((i==0?pre:t[i-1])=='S'?1:-1);
    if(k==-1) b*=-1;
    if(b==1){
      if(i==s.size()-1){
        end = 'S';
        break;
      }
      t+='S';
    }else {
      if(i==s.size()-1){
        end = 'W';
        break;
      }
      t+='W';
    }
  }
  if(pre==t[n-1]&&t[0]==end){
    std::cout << t << '\n';
    return 0;
  }
  //WW
  pre = 'W';
  t = "W";
  re(i, s.size()){
    int k = (s[i]=='o'?1:-1);
    if(t[i]=='W') k*=-1;
    int b = ((i==0?pre:t[i-1])=='S'?1:-1);
    if(k==-1) b*=-1;
    if(b==1){
      if(i==s.size()-1){
        end = 'S';
        break;
      }
      t+='S';
    }else {
      if(i==s.size()-1){
        end = 'W';
        break;
      }
      t+='W';
    }
  }
  if(pre==t[n-1]&&t[0]==end){
    std::cout << t << '\n';
    return 0;
  }
  //WS
  pre = 'W';
  t = "S";
  re(i, s.size()){
    int k = (s[i]=='o'?1:-1);
    if(t[i]=='W') k*=-1;
    int b = ((i==0?pre:t[i-1])=='S'?1:-1);
    if(k==-1) b*=-1;
    if(b==1){
      if(i==s.size()-1){
        end = 'S';
        break;
      }
      t+='S';
    }else {
      if(i==s.size()-1){
        end = 'W';
        break;
      }
      t+='W';
    }
  }
  if(pre==t[n-1]&&t[0]==end){
    std::cout << t << '\n';
    return 0;
  }
  std::cout << -1 << '\n';
  return 0;
}


Measured memory_bytes: 704
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;
map <int ,int> mpa,mpb;
#define MAX 10005
#define NIL -1

struct Node {int parent,left,right;};

Node T[MAX];
int n, D[MAX],H[MAX];

void setDepth(int u, int d){
  if(u == NIL) return;
  D[u] = d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}

int setHigh(int u){
  int h1=0, h2=0;
  if(T[u].left != NIL) h1=setHigh(T[u].left)+1;
  if(T[u].right != NIL) h2=setHigh(T[u].right)+1;

  return H[u]=(h1>h2 ? h1:h2);
}

int getSibling(int u){
  if(T[u].parent==NIL) return NIL;
  if(T[T[u].parent].left !=u && T[T[u].parent].left !=NIL)
    return T[T[u].parent].left;
  if(T[T[u].parent].right !=u && T[T[u].parent].right !=NIL)
    return T[T[u].parent].right;
  return NIL;
}

void print(int u){
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].parent);
  printf("sibling = %d, ", getSibling(u));
  int deg=0;
  if(T[u].left!=NIL) deg++;
  if(T[u].right!=NIL) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);

  if(T[u].parent==NIL){
    printf("root\n");
  }else if(T[u].left==NIL && T[u].right==NIL ){
    printf("leaf\n");
  }else{
    printf("internal node\n");
  }
}

int main(){
  int v,l,r,root=0;
  scanf("%d",&n);
  int i;
  for(i=0;i<n;i++) T[i].parent=NIL;//初期化

  for(i=0;i<n;i++){
  scanf("%d %d %d",&v,&l,&r);
  T[v].left=l;
  T[v].right=r;
  if(l !=NIL) T[l].parent=v;
  if(r !=NIL) T[r].parent=v;
  }

  for(i=0;i<n;i++) if(T[i].parent==NIL) root=i;

  setDepth(root,0);
  setHigh(root);

  for(i=0;i<n;i++) print(i);

  return 0;
}


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

int main(){
  ll n;
  cin >> n;
  ll sum = 0;
  for(int i = 1; i <= n; ++i){
  	if(i%3 == 0 || i%5 == 0) continue;
  	sum += i;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll INF = 1LL << 30;

int main(void){
    int A,B; cin >> A >> B;
    
    int ans = 0;
    for(int i = 0; i <= 20; i++){
        if(A + (i-1)*(A-1) >= B){
            ans = i;
            break;
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int K = scan.nextInt();
        int A = scan.nextInt();
        int B = scan.nextInt();

        for(int i = A; i <= B; i++) {
            if (i % K == 0){
                os.println("OK");
                return;
            }
        }

        os.println("NG");
    }
}

Measured memory_bytes: 27064
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int n;
char returneki[60];
map<char,long long int>eki;

int main() {
    cin>>n;
	for(char i='a';i<='z';i++){
		eki[i]=i-'a';
	}
	for(char i='A';i<='Z';i++){
		eki[i]=i-'A'+26;
	}
	for(int i=0;i<26;i++){
		returneki[i]='a'+i;
		returneki[i+26]='A'+i;
	}
	while(n!=0){
		long long int now=0,k[105];
		string str,res;
		for(int i=0;i<n;i++){
			cin>>k[i];
		}
		cin>>str;
		for(int i=0;i<str.length();i++){
			res+=returneki[(eki[str[i]]-k[now%n]+52)%52];
			now++;
		}
		cout<<res<<endl;
		cin>>n;
	}
	
} 



Measured memory_bytes: 3184
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <stack>
#include <cctype>

using namespace std;

/* typedef */

typedef long long ll;

/* constant */

const int INF = 1 << 30;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */

/* function */

void digit_sum(string S) {
    ll d_sum = 0;
    for (int i = 0; i < S.size(); i++) {
        d_sum += int(S[i]) - '0';
    }
    cout << d_sum << '\n';
}


/* main */
int main() {
    while (1) {
        string x; cin >> x;
        if (x == "0") return 0;
        digit_sum(x);
    }
}



Measured memory_bytes: 3224
// finish date: 2018/03/14

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


int main() {
    int x, y;
    cin >> x >> y;
    if (x <= y) {
        if (x < 0 && y > 0) cout << abs(abs(y) - abs(x)) + 1 << endl;
        else cout << y - x << endl;
    } else {
        if ((ll) x * y > 0) cout << abs(abs(y) - abs(x)) + 2 << endl;
        else cout << abs(abs(y) - abs(x)) + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	var dfs func(s string, mx int)
	dfs = func(s string, mx int) {
		if len(s) == n {
			fmt.Println(s)
			return
		}

		for c := int('a'); c <= mx; c++ {
			nmx := mx
			if c == mx {
				nmx++
			}
			dfs(s+string(c), nmx)
		}
	}
	dfs("", 'a')
}


Measured memory_bytes: 5888
import java.util.*;
 
class demand implements Comparable{
  int from;
  int to;
 
  public int compareTo(Object other){
    demand otherdemand = (demand)other;
    return to - otherdemand.to;
  }
}

public class Main {
  public static void main(String[] args) {
 	  Scanner sc = new Scanner(System.in);
 
    int n = sc.nextInt();
    int m = sc.nextInt();


    demand[] demands = new demand[m];

    for(int i = 0; i < m; i++){
      demand newdemand = new demand();
      newdemand.from = sc.nextInt();
      newdemand.to = sc.nextInt();
      demands[i] = newdemand;
    }

    Arrays.sort(demands);

    int ans = 0;
    int nowclear = 0;
    for(int i = 0; i < m; i++){
      int nowfrom = demands[i].from;
      int nowto = demands[i].to;
      if(nowclear < nowfrom){
        ans++;
        nowclear = nowto - 1;
      }
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 82544
#include<bits/stdc++.h>
#define int long long
#define out(x) cerr << #x << " = " << x << "\n"
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
	x = 0;char c = getchar();bool f = 0;
	for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
	for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
	if(f) x = -x;
}
const int N = 1e6 + 10 ;
int n, ans = 0 ,now = 0;
struct E {
	int u, v, w;
}e[N << 2];
int cnt = 0;
inline void add(int u, int v, int w) {
	e[++ cnt] = (E) {u, v, w};
}
struct P {
	int F, S, id;
}p[N];
int pre[N];
inline bool cmp_x(P a, P b) {
	return a.F < b.F || a.F == b.F && a.S < b.S;
}
inline bool cmp_y(P a, P b) {
	return a.S < b.S || a.S == b.S && a.F < b.F;
}
inline bool cmp_edge(E a, E b) {
	return a.w < b.w;
}
inline int find(int u) {
	return pre[u] == u ? u : pre[u] = find(pre[u]);
}
main() {
	read(n);	
	for(int i = 1; i <= n; i ++) {
		read(p[i].F), read(p[i].S);
		p[i].id = i;
	}	
	sort(p + 1, p + n + 1, cmp_x);
	for(int i = 2; i <= n; i  ++) {
		add(p[i].id, p[i - 1].id, min(abs(p[i].F - p[i - 1]. F), abs(p[i].S - p[i - 1]. S)));
	}
	sort(p + 1, p + n + 1, cmp_y);
	for(int i = 2; i <= n; i  ++) {
		add(p[i].id, p[i - 1].id, min(abs(p[i].F - p[i - 1]. F), abs(p[i].S - p[i - 1]. S)));
	}
	sort(e + 1, e + cnt + 1, cmp_edge);
	for(int i = 1; i <= n; i ++) pre[i] = i;
	for(int i = 1; i <= cnt; i ++) {
		int fx = find(e[i].u), fy = find(e[i].v) ;
		if(fx != fy) pre[fx] = fy, ans += e[i].w;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 11264
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int a, b, c;
	cin >> a >> b >> c;
	if (a+b+c > 21) cout << "bust" << endl;
	else cout << "win" << endl;
	
	//cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

                Scanner scan = new Scanner(System.in);
                String[] a = scan.nextLine().split("");

                int count = 0;
                if("1".equals(a[0]))
                    count++;

                if("1".equals(a[1]))
                    count++;
                if("1".equals(a[2]))
                    count++;
                System.out.print(count);

            }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const ll INF = LLONG_MAX/3;

/*-----Library-----*/

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

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); sizeuf.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizeuf[i]=1;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        sizeuf[x]+=sizeuf[y];
        return true;
    }

    int size(int x){
        return sizeuf[root(x)];
    }
};

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

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}
//コンビネーション
/*
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 */
/*-----Library-----*/
const int MOD=1234567;
signed main(){
	int n;
	cin>>n;
	int ans=0;
	rep(i,n){
		int a;
		cin>>a;
		ans+=a;
		ans-=i+1;
	}
	cout<<ans<<endl;
}



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

int main() {
    int N, K,number = 1;
    cin >> N>> K;
    
    rep(i,N){
        if (number > K){
            number += K;
        }
        else{
            number *= 2;
        }
    }
    cout << number << endl;
    
}

Measured memory_bytes: 3580
while True:
    H,W = map(int, input().split())
    
    if H == 0 and W == 0:
        break
    for i in range(H):
        if i == 0 or i == H - 1:
            print('#' * W)
        else:
            print('#' + '.' * (W - 2) + '#')
    print()


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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(n % 2){
        cout << "No" << endl;
    }else{
        int ok = 1, del = n / 2;
        for(register int i = 1; i <= del; ++i){
            if(s[i - 1] != s[i + del - 1]){
                ok = 0;
                break;
            }
        }
        if(ok){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll A, X;
    cin >> A >> X;

    ll ans = 500 * A;

    if(ans >= X){
        cout << "Yes" << endl;
    }else{  
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
def delete_head_zeros(n):
	n = str(n)
	l = len(n)
	if "." in n:
		l = n.find(".")
	head_zeros = 0
	for i in range(l - 1):
		if n[i] == "0":
			head_zeros += 1
		else:
			break

	return n[head_zeros:]

# compare a, b
# a, b: int or string
def bigint_compare(a, b):
	a = delete_head_zeros(a)
	b = delete_head_zeros(b)
	if len(a) > len(b):
		return 1
	elif len(a) < len(b):
		return -1
	else:
		if a > b:
			return 1
		elif a < b:
			return -1
		else:
			return 0

# calculate a + b
# a, b: int or string
def bigint_plus(a, b):
	a = str(a)
	b = str(b)

	d = max([len(a), len(b)])
	a = '0' * (d - len(a)) + a
	b = '0' * (d - len(b)) + b

	ans = ""
	carry = 0
	for i in range(d):
		s = int(a[-i-1]) + int(b[-i-1]) + carry
		carry = s // 10
		ans = str(s % 10) + ans
	else:
		if carry:
			ans = str(carry) + ans

	return ans

# calculate a - b
# a, b: int or string
def bigint_minus(a, b): 
	a = str(a)
	b = str(b)
	M = []
	m = []
	sign = ""

	if len(a) > len(b) or (len(a) == len(b) and a >= b):
		[M, m] = [a, b]
	else:
		[M, m] = [b, a]
		sign = "-"
	m = '0' * (len(M) - len(m)) + m

	ans = ""
	borrow = 0
	for i in range(len(M)):
		s = int(M[-i-1]) - int(m[-i-1]) - borrow
		if s < 0:
			borrow = 1
			s += 10
		else:
			borrow = 0
		ans = str(s) + ans

	return sign + delete_head_zeros(ans)

# calculate a * b
# a, b: int or string
def bigint_multiply(a, b):
	a = str(a)
	b = str(b)

	md = []
	for j in range(len(b)):
		carry = 0
		mj = ""
		for i in range(len(a)):
			m = int(a[-i-1]) * int(b[-j-1]) + carry
			carry = m // 10
			mj = str(m % 10) + mj
		else:
			if carry:
				mj = str(carry) + mj
		md.append(mj)

	ans = 0
	for k in range(len(md)):
		ans = bigint_plus(md[k] + "0" * k, ans)

	return ans


# calculate a / b to d digits after decimal point
# a, b, d: int or string
def bigint_divide(a, b, d = 0):
	a = str(a)
	b = str(b)
	d = int(d)
	if d < 0:
		d = 0

	ans = ""
	r = ""
	for i in range(len(a) + d):
		q = 0
		if i < len(a):
			r += a[i]
		elif i == len(a):
			ans += "."
			r += "0"
		else:
			r += "0"

		if bigint_compare(r, b) == -1:
			ans += str(q)
		else:
			while bigint_compare(r, b) >= 0:
				r = bigint_minus(r, b)
				q += 1
			ans += str(q)

	return delete_head_zeros(ans)

def main():
	N, X = input().split(" ")
	layer = [1]
	patties = [1]
	for i in range(int(N)):
		layer.append(bigint_plus(bigint_multiply(layer[-1], 2), 3))
		patties.append(bigint_plus(bigint_multiply(patties[-1], 2), 1))

	def count_patty(L, Y, P): # Y, P : bigint
		if L == 0:
			return bigint_plus(P, 1)
		center = bigint_divide(bigint_plus(layer[L], 1), 2)
		if Y == "1":
			return P
		elif Y == layer[L]:
			return bigint_plus(P, patties[L])
		elif bigint_compare(Y, center) == 0:
			return bigint_plus(bigint_plus(P, 1), patties[L - 1])
		elif bigint_compare(Y, center) == 1:
			return count_patty(L - 1, bigint_minus(Y, center), bigint_plus(bigint_plus(P, patties[L - 1]), 1))
		elif bigint_compare(Y, center) == -1:
			return count_patty(L - 1, bigint_minus(Y, 1), P)

	print(count_patty(int(N), X, "0"))

main()

Measured memory_bytes: 9284
n, k = gets.chomp.split.map(&:to_i)

max = (n-1)*(n-2)/2
if max < k
  puts(-1)
else
  puts((n-1) + (max - k))
  (2..n).each do |i|
    puts("1 #{i}")
  end
  count = 0
  (2..(n-1)).each do |i|
    break if count >= max - k
    ((i+1)..n).each do |j|
      break if count >= max - k
      puts("#{i} #{j}")
      count += 1
    end
  end
end

Measured memory_bytes: 1788
//  aoj -  - A  / 2016-03-06
#include<iostream>
#include<vector>
#include<cassert>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<tuple>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef ll int__;
#define rep(i,j) for(int__ i=0;i<(int__)(j);i++)
#define repeat(i,j,k) for(int__ i=(j);i<(int__)(k);i++)
#define all(v) v.begin(),v.end()

template<typename T>ostream& operator << (ostream &os , const vector<T> &v){
    rep(i,v.size()) os << v[i] << (i!=v.size()-1 ? " " : "\n"); return os;
}
template<typename T>istream& operator >> (istream &is , vector<T> &v){
    rep(i,v.size()) is >> v[i]; return is;
}

#ifdef DEBUG
void debug(){ cerr << endl; }
#endif
template<class F,class...R> void debug(const F &car,const R&... cdr){
#ifdef DEBUG
    cerr << car << " "; debug(cdr...);
#endif
}

double norm(double x, double y){
    return sqrt(x*x + y*y);
}

bool solve(){
    int N; cin >> N;
    int f[2], a[2], t[2], x[2], y[2];
    double ans_d[2] = {-1, -1};
    double ans_t[2] = {-1, -1};
    rep(i, N){
        cin >> f[i%2] >> a[i%2] >> t[i%2] >> x[i%2] >> y[i%2];
        if(i == 0) continue;
        if( t[i%2] == t[(i+1)%2] and a[i%2] != a[(i+1)%2] ){
            double d = norm(x[0] - x[1], y[0] - y[1]);
            if(abs(ans_d[t[0]] - d) < 1e-8){
                ans_t[t[0]] = min(ans_t[t[0]], (f[i%2] - f[(i+1)%2]) / 60.0);
            } else if(ans_d[t[0]] < d){
                ans_d[t[0]] = d;
                ans_t[t[0]] = (f[i%2] - f[(i+1)%2]) / 60.0;
            }

        }
    }
    rep(i, 2){
        printf("%.6f %.6f\n", ans_d[i], ans_t[i]);
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    while(solve());
    return 0;
}

Measured memory_bytes: 3252
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, h, a[100010], b[100010], ma = 0;
	cin >> n >> h;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		ma = max(ma, a[i]);
	}
	ll cnt = 0, yan[100010];
	for (int i = 0; i < n; i++) {
		if (b[i] > ma) {
			yan[cnt] = b[i]; 
			cnt++;
		}
	}
	sort(yan, yan + cnt);
	for (int i = cnt - 2; i >= 0; i--)yan[i] += yan[i + 1];
	ll yojo, ans = (h + ma - 1) / ma, num;
	for (int i = 0; i < cnt; i++) {
		yojo = h;
		yojo -= yan[i];
		num = cnt - i;
		if (yojo > 0) {
			num += (yojo + ma - 1) / ma;
		}
		ans = min(ans, num);
	}
	cout << ans << endl;
	return 0;
}


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

if N == 3 :
    print(2, 5, 63)
    
elif N == 4 :
    print(2, 5, 20, 63)
    
else :
    ret = [2, 4, 6]
    
    i = 3
    while N - len(ret) >= 2 and i + 6 <= 30000 :
        ret.append(i)
        ret.append(i + 6)
        i += 12

    i = 8
    while N - len(ret) >= 3 and i + 4 <= 30000 :
        ret.append(i)
        ret.append(i + 2)
        ret.append(i + 4)
        i += 6
        
    if N - len(ret) == 2 :
        ret.append(29996)
        ret.append(29998)
        
    elif N - len(ret) == 1 :
        ret.append(30000)
            
    print(*ret)

Measured memory_bytes: 41840
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
using namespace std;

int main(){
    char coffee[6];
    cin >> coffee;
    if(coffee[2]==coffee[3] && coffee[4] == coffee[5]){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define pi(n,m) n.insert(n.begin(),m);
#define ee(n) n.erase(n.end()-1)
#define eb(n) n.erase(n.begin())
#define check(n) reverse(all(n));rep(z,0,n.size())cout<<n[z];co("");reverse(all(n));
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int a,b;
  cin>>a>>b;
  co(a*b);
  
  return 0;
}

Measured memory_bytes: 3632
import math
def main():
    S = int(input())
    t = int(math.sqrt(S))
    if t * t == S:
        print("0 0", t, "0 0", t)
        return
    x = (t+1) * (t+1) - S
    print("0 0 1", t+1, t+1, x)
    return
main()
    


Measured memory_bytes: 2940
s = input()
old = ''
flag = 0
sample = [chr(i) for i in range(97, 97+26)]
if len(s) == 26:
    u = {s[-1]}
    for i in range(len(s) - 1)[::-1]:
        x = [c for c in u if s[i] < c]
        if x:
            out = s[:i] + min(x)
            break
        u.add(s[i])
    else:
        out = -1
    # for i, s1 in enumerate(s[::-1]):
    #     if i != 0 and s1 < min(old):
    #         out = s[:len(s)-i-1] + min(old)
    #         flag = 1
    #         break
    #     old += s1
    #     if flag == 0:
    #         out = -1
else:
    out = s + min(set(sample)-set(s))

print(out)


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

using namespace std;

int main(void) {
  long long X; cin >> X;
  vector<int> prime;
 
  prime.push_back(1);
  for (int i = 1; i * i <= X; i++) {
    if (X%i == 0) {
      prime.push_back(i);
      prime.push_back(X/i);
    }
  }
  prime.push_back(X);

  for (int i = 0; i < prime.size(); i++) {
    long long b = -1, a = b+prime[i];
    long long c = X/prime[i];
    for (int i = -200; i < 200; ++i) {
      if (c == (a+i)*(a+i)*(a+i)*(a+i) + (a+i)*(a+i)*(a+i)*(b+i)
              +(a+i)*(a+i)*(b+i)*(b+i) + (a+i)*(b+i)*(b+i)*(b+i)
              +(b+i)*(b+i)*(b+i)*(b+i)) {
        cout << a+i << " " << b+i << endl;
        return 0;
      }
    }
  }

  return 0;
}

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

int main(){
    string s;
    int k;
    cin >> k;
    cin >> s;
    for(int i=1;i<=100;i++){
        if(i>k){
            cout << "..." << endl;
            break;
        }
        cout << s[i-1];
        if(i==s.size()){
            cout << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3596
A, B, C = map(int, input().split())
S = A+B+C

k = 0
flag = 0
while k<100:
    if A%2==1 or B%2==1 or C%2==1 or min([A,B,C])<1:
        flag = 1
        break
    An = (B + C)//2
    Bn = (A + C)//2
    Cn = (B + A)//2
    A = An 
    B = Bn 
    C = Cn         
    k += 1

if not flag:
    k = -1

print(k)

Measured memory_bytes: 9132
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

vvpll G;
vl visited;
vl d(MAX_N);
bool ok = true;

void dfs(ll v, ll dist) {
    if(visited[v]) {
        if(d[v] != dist) {
            ok = false;
            return;
        }
        return;
    }
    visited[v] = 1;
    d[v] = dist;
    for(auto p : G[v]) {
        ll u = p.first;
        ll cost = p.second;
        dfs(u, d[v] + cost);
    }
    return;
}

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

    G.resize(n);
    rep(i, m) {
        ll L, R, D;
        cin >> L >> R >> D;
        L--;  R--;
        G[L].pb(make_pair(R, D));
        G[R].pb(make_pair(L, -D));
    }

    visited.resize(n);
    rep(v, n) {
        if(!visited[v]) {
            dfs(v, 0);
        }
    }

    if(ok) {
        out("Yes");
    }
    else {
        out("No");
    }
    
    re0;
}

Measured memory_bytes: 16384
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#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++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
int exp(int x,int y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    int t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

int main(){
  int n,k;string s;cin >> n >> s >> k;k--;
  rep(i,n){
    if(s[i]==s[k])cout << s[k];
    else cout << '*';
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define MAX 1000
 
int lcs(char *,char *);
char A[MAX+1],B[MAX+1];
 
int main(){
  int n,i;
 
   
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%s",A);
    scanf("%s",B);
    printf("%d\n",lcs(A,B));
  }
  return 0;
}
 
int lcs(char *A,char *B){
  int m,n,i,j;
  int C[MAX+2][MAX+2];
 
  int max=0;
   
  m=strlen(A);
  n=strlen(B);
   
  for(i=0;i<=m;i++){
    C[i][0]=0;
  }
  for(j=0;j<=n;j++){
    C[0][j]=0;
  }
  for(i=1;i<=m;i++){
    for(j=1;j<=n;j++){
      if(A[i-1]==B[j-1]){
    C[i][j]=C[i-1][j-1]+1;
      }
      else if(C[i-1][j]>=C[i][j-1]){
    C[i][j]=C[i-1][j];
      }
      else C[i][j]=C[i][j-1];
      if(C[i][j]>max) max= C[i][j];
 
    }
  }
  return C[m][n];
}

Measured memory_bytes: 4528
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
using ll = long long;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
int main(){
  ll n;
  cin >> n;
  ll h[n];
  rep(i,n){
    cin >> h[i];
  }
  ll sum=0;
  ll piv = 0;
  while(piv != n){
    if(h[piv]==0){
      piv++;
    }else{
      h[piv]--;
      sum++;
      for(int i=piv+1;i<n;i++){
        if(h[i] != 0){
          h[i]--;
        }else{
          break;
        }
      }
    }
  }
  cout << sum;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int A, B;
  cin >> A >> B;
  int ans1 = A + (A - 1);
  int ans2 = A + (B - 1);
  int ans3 = B + (A - 1);
  int ans4 = B + (B - 1);
  int ans5 = A + B;
  cout << max(max(ans1, max(ans2, ans3)), max(ans4, ans5)) << endl;
  return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int, input().split()))

results = [0]*(n+1)
for i in range(n-k):
  if a[i] < a[i+k]:
    results[i+k+1] = 'Yes'
  else:
    results[i+k+1] = 'No'

for i in range(k+1,n+1):
  print(results[i])

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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

int main(){
    bool flag=false;
    ll ans=0,sum=0;

    int n,p;
    string s;
    cin>>n>>p>>s;

    if(p==2){

        rep(i,n){
            int d = s[i]-'0';
            if(d%2==0)ans += (i+1);
        }

    }else if(p==5){

        rep(i,n){
            int d = s[i]-'0';
            if(d==5 || d==0)ans += (i+1);
        }

    }else{

        vector<int> mP(n,0);
        map<int,ll> mfq;

        mP[n-1] = ( (s[n-1]-'0') %p);
        mfq[ mP[n-1] ]++;
        mfq[0]++;

        int Md = 1;
        rep1(i,1,n){
            int pr = n-i;
            int pos = pr-1;
            Md = (Md*10)%p;

            mP[pos] = ( mP[pr]+(s[pos]-'0')*Md )%p;
            mfq[ mP[pos] ]++;
        }

        for(auto p:mfq){
            ll ap = p.second;
            ans += max(ap*(ap-1)/2,0LL);
        }

    }

    //cout <<fixed<<setprecision(16)<< << endl;
    
    cout<<ans<<endl;
    
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 1796
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<Int, Int> P;

int main(){
    int X, Y; cin >> X >> Y;

    bool flag = false;
    rep(i,100)rep(j,100){
        if(i+j==X && 2*i+4*j==Y) flag = true;
    }

    if(flag){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

int fill(int field[50][50], int x, int y, int w, int h){
    if(field[x][y] == 1){
        field[x][y] = 0;
        if(x+1<w) fill(field, x+1, y, w, h);
        if(y+1<h) fill(field, x, y+1, w, h);
        if(x-1>=0) fill(field, x-1, y, w, h);
        if(y-1>=0) fill(field, x, y-1, w, h);
        if(x+1<w && y+1<h) fill(field, x+1, y+1, w, h);
        if(x+1<w && y-1>=0) fill(field, x+1, y-1, w, h);
        if(x-1>=0 && y+1<h) fill(field, x-1, y+1, w, h);
        if(x-1>=0 && y-1>=0) fill(field, x-1, y-1, w, h);
        return 1;
    }
    return 0;
}

int main(){
    int w, h;
    int field[50][50];
    int result;
    cin >> w >> h;
    while(w || h){
        result = 0;
        for(int i=0;i<h;++i){
            for(int j=0;j<w;++j){
                cin >> field[j][i];
            }
        }
        for(int i=0;i<h;++i){
            for(int j=0;j<w;++j){
                result += fill(field, j, i, w, h);
            }
        }
        cout << result << endl;
        cin >> w >> h;
    }
}

Measured memory_bytes: 1352
//デバッグ用オプション：-fsanitize=undefined,address

//コンパイラ最適化
#pragma GCC optimize("Ofast")

//インクルードなど
#include <algorithm> 
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

// vector set 等
#include <map>
#include <set>
#include <vector>

//マクロ
// forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
// FORAは範囲for文(使いにくかったら消す)
#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--)
#define FORA(i, I) for (const auto& i : I)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF 1000000000000  // 10^12:∞
#define MOD 1000000007     // 10^9+7:合同式の法
#define MAXR 100000        // 10^5:配列の最大のrange
//略記
#define PB push_back  //挿入
#define MP make_pair  // pairのコンストラクタ
#define F first       // pairの一つ目の要素
#define S second      // pairの二つ目の要素

// 負の数にも対応した % 演算
ll mod(ll x) {
  ll res = x % MOD;
  if (res < 0) x += MOD;
  return res;
}

ll mpow(ll x, ll n) {
  ll res = 1;
  while (n != 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n = n >> 1;
  }
  return res;
}

// a^{-1} mod を計算する
ll minv(ll a) { return mpow(a, MOD - 2); }

signed main() {
  //入力の高速化用のコード
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int h,w,m, max_h, max_w, ans;
  max_h = 0;
  max_w = 0;
  
  cin >> h>>w>>m;

  vector<int> count_h(h+10);
  vector<int> count_w(w+10);

  map<int,map<int,bool>> masu{};

  int _h, _w;
  REP(i, m) { 
      cin >> _h >> _w;
      count_h[_h] +=1;
      count_w[_w] +=1;
      masu[_w][_h] = true;
  }

  // cout <<max_w<< " -- "<<max_h<<endl;
  max_h = *max_element(ALL(count_h));
  max_w = *max_element(ALL(count_w));

  map<int,bool> mp;
  set<int> items_h,items_w;
  FOR(i,1, w) {
    if(max_w == count_w[i]){
      items_w.insert(i);
    }
  }
  FOR(i,1,h) {
    if(max_h == count_h[i]){
      items_h.insert(i);
    }
  }
  FORA(i_w, items_w) {
    mp = masu[i_w];
    FORA(i_h, items_h) {
      if(!mp[i_h]){
          cout << max_h + max_w << endl;
          return 0;
        }
      }
  }
  cout << max_h + max_w -1 << endl;
  return 0;
}


Measured memory_bytes: 70584
#include<stdio.h>
#define MAX 100

int binarySearch( int );

int n,A[100000];

int main(){
  int i,j,q,k,sum=0;

  scanf("%d",&n);

  for( i = 0 ; i < n ; i++ ){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);

  for( j = 0 ; j < q ; j++ ){
    scanf("%d",&k);

    if( binarySearch(k) == 1 ) sum++;

  }
  
  printf("%d\n",sum);

  return 0;
}

int binarySearch( int x ){
  int left = 0;
  int right = n;

  while( left < right ){
    int mid = ( left + right ) / 2;

    if( A[mid] == x ) return 1;

    else if( x < A[mid] ) right = mid;

    else left = mid + 1;
  }
  return 0;
}

Measured memory_bytes: 988