akhauriyash/Code-Regression huggingface dataset:
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, m) revi(i, m, 0)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int N;
  st S;
  ci(N, S);
  int a = 0, c = 0;
  rep(i, N){
    if(S.at(i) == 'I'){
      c++;
    }
    else{
      c--;
    }
    a = max(a, c);
  }
  co(a);
}

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

using namespace std;

int main() {
  int64_t Q, H, S, D, N;
  cin >> Q >> H >> S >> D >> N;
  auto precost = min(2 * Q, H);
  auto cost = min(2 * precost, S);
  cout << min(N * cost, N / 2 * D + (N % 2 == 1 ? cost : 0)) << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;
int main() 
{
    int n,m;
    int a[n+10];

    cin >> n >> m;
    int sum=0;
    rep(i,n){
        cin >> a[i];
        sum+=a[i];
    }
    sort(a,a+n,std::greater<>());
    double x;
    x=sum/4.0/m;
    if(a[m-1]<x){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("myfile.in","r",stdin);freopen ("myfile.out","w",stdout);
#define mod 1000000007
#define fs(x,y) for(int i=1;i<=y;i++) cin>>x[i];
#define fo(i,x,y) for(int i=x;i<=y;i++)
using namespace std;

ll n,m,ar[25][25],b[25],sum,top,c;


int main()
{
	fast;
	cin>>n>>m>>c;
	for(int i=1;i<=m;i++)
		cin>>b[i];
	for(int i=1;i<=n;i++)
	{
		top=0;
		int tmp;
		for(int j=1;j<=m;j++)
			cin>>tmp,top+=b[j]*tmp;
		if(top+c>0)
			sum++;
	}
	cout<<sum;


}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;


int main() {

    int N;
    cin >> N;
    int a[N];
    int ans[100];
    double sum=0;
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    for(int i=0;i<100;i++){
        ans[i] = 0;
    }
    
    for(int i=0;i<100;i++){
        for(int j=0;j<N;j++){
            ans[i]+=(a[j]-(i+1))*(a[j]-(i+1));   
        }
    }
    sort(ans,ans+100);
    cout << ans[0] << endl;
    return 0;
}

Measured memory_bytes: 256
# include<iostream>
# include<algorithm>
# include<cctype>
# include<cstdio>
# include<cstring>
# include<sstream>
# include<cmath>
# include<limits.h>
using namespace std;
long long n, a[101], f[101];
int main()
{
      cin >> n;
      for (int i=0; i<n; i++)
      {
            cin>> a[i];
      }
      long long minn=LONG_MAX;
      for (int i=1; i<=100; i++)
      {
            f[i] = 0;
            for (int j=0; j<n; j++)
            {
                  f[i] += (a[j]-i)*(a[j]-i);
            }
            minn=min(minn, f[i]);
      }
      cout << minn << endl;
      return 0;
}



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

typedef long long ll;

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

    ll one;
    ll left = 0, right = 0;
    if(a % 2 == 0){
        if(b % 2 == 0){
            one = (b - a) / 2;
            right = b;
        }
        else{
            one = (b - a + 1) / 2;
        }
    }
    else{
        left = a;
        if(b % 2 == 0){
            one = (b - a - 1) / 2;
            right = b;
        }
        else{
            one = (b - a) / 2;
        }
    }

    one %= 2;
    ll ans = left ^ one ^ right;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <math.h>

#define MINV 1.0E-15

using namespace std;

class Point {
public:
    double _x, _y;
    Point(): _x(0), _y(0){}
    Point(double x, double y): _x(x), _y(y){}
    Point(const Point& a): _x(a._x), _y(a._y){}

    Point operator+(const Point& a) const{
        return Point(_x + a._x, _y + a._y);
    }
    Point operator-(const Point& a) const{
        return Point(_x - a._x, _y - a._y);
    }
    Point operator*(double& a) const{
        return Point(_x*a, _y*a);
    }
    Point operator/(double& a) const{
        return Point(_x/a, _y/a);
    }
    void operator=(const Point& a){
        _x = a._x;
        _y = a._y;
    }
    double dot(const Point& a) const{
        return (_x*a._x + _y*a._y);
    }
    double norm() const{
        return sqrt(_x*_x + _y*_y);
    }
};

Point operator*(double a, const Point& vec){
    return vec*a;
}
Point operator/(double a, const Point& vec){
    return vec/a;
}

double cross(const Point& p0, const Point& p1){
    return p0._x * p1._y - p0._y*p1._x;
}

int ccw(Point a, Point b){
    double ret=cross(a,b);
    if(ret > MINV){
        return 1;
    }else if( (-ret) > MINV ){
        return 2;
    }
    if(a.dot(b) < 0) return 3;
    if(a.norm() < b.norm()){
        return 4;
    }else{
        return 5;
    }

}

typedef Point Vec;

int main(){
    double x0,y0,x1,y1,x2,y2;
    scanf("%lf %lf %lf %lf", &x0, &y0, &x1, &y1);
    Vec p0(x0,y0), p1(x1,y1), a(p1-p0), p2;

    int q;
    scanf("%d",&q);

    for(int i=0; i<q; ++i){
        scanf("%lf %lf",&x2,&y2);
        p2 = Vec(x2,y2);
        int ret = ccw(a,p2-p0);
        switch(ret){
case 1:
            cout << "COUNTER_CLOCKWISE" << endl;
            break;
case 2:
            cout << "CLOCKWISE" << endl;
            break;
case 3:
            cout << "ONLINE_BACK" << endl;
            break;
case 4:
            cout << "ONLINE_FRONT" << endl;
            break;
case 5:
            cout << "ON_SEGMENT" << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3312
#include "bits/stdc++.h"
using namespace std;

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

    long long k,a,b;
    cin >> k >> a >> b;

    long long ans = 1;

    if(b > a+2){
        for(int i = 0; i < k; i++){
            if(ans >= a && i + 1 < k){
                ans += b-a;
                i++;
            }else{
                ans++;
            }
        }
    }else{
        ans = k+1;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
io = STDIN
n,m,q=io.gets.split.map(&:to_i)
abcd=q.times.map{io.gets.split.map(&:to_i)}
def scores(ar,abcd)
  abcd.map do |a,b,c,d|
    ar[b-1]-ar[a-1]==c ? d : 0
  end
end
ans=0
(1..m).to_a.repeated_combination(n).each do |ar|
  ans=[scores(ar,abcd).sum,ans].max
end
p ans


Measured memory_bytes: 15568
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n;
    string s; cin >> s;
    vll r, g, b;
    rep(i, s.size()) {
        switch (s[i]) {
            case 'R':
                r.push_back(i);
                break;
            case 'G':
                g.push_back(i);
                break;
            case 'B':
                b.push_back(i);
                break;
        }
    }

    ll sum = r.size() * g.size() * b.size();
    rep(i, r.size()) {
        rep(j, g.size()) {
            ll under = min(r[i], g[j]);
            ll above = max(r[i], g[j]);

            ll diff = above - under;
            ll low = under - diff;
            ll high = above + diff;
            ll middle = under + diff / 2;

            sum -= (0 <= low && s[low] == 'B') + (high < n && s[high] == 'B') + (diff % 2 == 0 && s[middle] == 'B');
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3652
// ░█████╗░░░░░░░░░░░░░░░
// ██╔══██╗░░██╗░░░░██╗░░
// ██║░░╚═╝██████╗██████╗
// ██║░░██╗╚═██╔═╝╚═██╔═╝
// ╚█████╔╝░░╚═╝░░░░╚═╝░░
// ░╚════╝░░░░░░░░░░░░░░░
#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define f(ii,n) for(ii=0;ii<n;ii++)
#define F(ii,a,n) for(ii=a;ii<n;ii++)
#define read0(array,n) for(ll i=0;i<n;i++) cin>>array[i];
#define read1(array,n) for(ll i=1;i<=n;i++) cin>>array[i];
#define inf 1000000007;
// function to transform string to lowercase --> transform(s.begin(),s.end(),s.begin(),::tolower)
//(a + b ) % m = (a % m + b % m ) %m
//(a - b ) % m = ( (a % m - b % m ) + m ) %m
//(a * b ) % m = (a % m * b % m ) %m
//(a / b ) % m = (a % m * inv(b) ) %m where inv(b) = pow(b,m,m-2)



ll power(ll i,ll j){
	ll prod=1;
	while(j>0){
		if(j&1){
			prod=prod*i;
		}
		j=j>>1;
		i=i*i;
	}
	return prod;
}

void solve(){
	ll i,j,n,m,k;
	cin>>n;
	string s=to_string(n);
	ll num=s[s.size()-1]-'0';
	if(num==2||num==4||num==5||num==7||num==9){
		cout<<"hon\n";
	}
	else if(num==0||num==1||num==6||num==8){
		cout<<"pon\n";
	}
	else{
		cout<<"bon\n";
	}

}
int main(){
	// freopen("filename.txt","r",stdin);
	solve();
	// ll t;
	// cin>>t;
	// while(t--){
	// 	solve();
	// }
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) v.begin(),v.end()
#define UN(v) sort(ALL(v)),v.erase(unique(ALL(v)))
#define FILL(x,y) memset(x,y,sizeof(x))
#define EACH(v,it) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define FIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
int deep[100005];
int par[100005];
int indeg[100005];
int n,m;
vector<int> E[100005];
int root;
/*---main code---*/

int DFS(int x)
{
	if(deep[x]!=-1)
	{
		return deep[x];
	}
	deep[x]=0;
	EACH(E[x],it)
	{
		int y=*it;
		deep[x]=max(deep[x],DFS(y)+1);
	}
	return deep[x];
}

void solve(int x,int p)
{
	if(par[x]!=-1)
	{
		return ;
	}
	par[x]=p;
	vii ch;
	EACH(E[x],it)
	{
		int y=*it;
		ch.push_back(pii(deep[y],y));
	}
	sort(ALL(ch));
	reverse(ALL(ch));
	EACH(ch,it)
	{
		solve(it->second,x);
	}
}

int main()
{
	FIO;
	cin>>n>>m;
	FILL(deep,-1);
	FILL(par,-1);
	for(int i=1;i<n+m;i++)
	{
		int x,y;
		cin>>x>>y;
		E[x].push_back(y);
		indeg[y]++;
	}
	for(int i=1;i<=n;i++)
	{
		if(indeg[i]==0)
		{
			root=i;
			break;
		}
	}
	DFS(root);
	solve(root,0);
	for(int i=1;i<=n;i++)
	{
		cout<<par[i]<<'\n';
	}
	return 0;
}


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

int main(){
    long long A,B,C,K;
    cin >> A >> B >> C >> K;
    long long sum = 0LL;
    long long k = K;
    if(K <= A){
        sum = K;
    }else{
        sum += A;
        k -= A;
        if(k > B){
            k -= B;
            sum -= k;
        }
    }
    cout << sum << endl;
    return 0;
}

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

int main () {

    string S;
    cin >> S;

    bool isBad = false;

    for (int i = 0; i < S.size()-1; i++) {
        if (S[i] == S[i+1]) {
            isBad = true;
        }
    }

    cout << ((isBad)? "Bad" : "Good") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int n, m,i;
    scanf("%d", &n);

    m = n;
    for(i=0;m>=4;i++){
        m-=4;
    }
    if(m==0){
        printf("Yes");
        return 0;
    }
    while(1){
        if(i<=0){
            printf("No");
            return 0;
        }
        RE:
        m=n;
        m-=(i-1)*4;
        if(m<7){
            i--;
            goto RE;
        }
        if(m%7==0){
            printf("Yes");
            return 0;
        }
        if(m==0){
            printf("No");
            return 0;
        }
        i--;
    }
    printf("Error");
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int y = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        Integer[] p = new Integer[a];
        Integer[] q = new Integer[b];
        Integer[] r = new Integer[c];
        Arrays.setAll(p, i -> Integer.parseInt(sc.next()));
        Arrays.setAll(q, i -> Integer.parseInt(sc.next()));
        Arrays.setAll(r, i -> Integer.parseInt(sc.next()));

        // 主処理
        PriorityQueue<Integer> eat = new PriorityQueue<>();
        Arrays.sort(p, Collections.reverseOrder());
        for (int i = 0; i < x; i++) {
            eat.add(p[i]);
        }
        Arrays.sort(q, Collections.reverseOrder());
        for (int i = 0; i < y; i++) {
            eat.add(q[i]);
        }
        for (int num : r) {
            eat.add(num);
            eat.poll();
        }
        long result = eat.stream().mapToLong(i -> i).sum();

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 70828
#include<stdio.h>

int main()
{
 char s[3];
 char flag[3];  
   scanf("%s",&s);
   for(int i=0;i<3;i++)
   {
    flag[i]=0;
   }
  
   for(int i=0;i<3;i++)
   {
     if(s[i]=='a')
     {
      flag[0]=1;
     }
     if(s[i]=='b')
     {
      flag[1]=1;
     }
     if(s[i]=='c')
     {
      flag[2]=1;
     }
   }
  if(flag[0]==1&&flag[1]==1&&flag[2]==1)
    printf("Yes");
  else
    printf("No");
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define pb      push_back
#define all(v)  v.begin(),v.end()
#define see(x)  cout<<#x<<" : "<<(x)<<endl;
#define ya      cout<<"Yes"<<endl;
#define no      cout<<"No"<<endl;
#define ff      first
#define sc      second
typedef long long ll;
typedef pair<ll,ll> pii;

void solve()
{
    ll k,i,j,ans=0;
    cin>>k;
    ll tot=0;
    for(i=1;i<=1e7;i++)
    {
        tot=(tot*10+7)%k;
        ans++;
        if(tot==0)
        {
            cout<<ans<<endl;
            return ;
        }
    }
    cout<<-1<<endl;
}

int main()
{
    solve();
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int n;
    cin >> n;
    vi ans(n);
    rep(i, n-1) {
        int a;
        cin >> a;
        ans[a-1]++;
    }
    rep(i, n) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 4024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
#define intxt freopen("in.txt","r",stdin)
const int maxn=1e6+10;
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
inline void umax(int &p,int q){if(p<q)p=q;}
inline void umin(int &p,int q){if(p>q)p=q;}
inline ll read()
{
    ll x=0;int f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,k,t,a,b;
ll ans;
int main()
{
    int i,j;
    scanf("%d%d%d",&n,&a,&b);
    rep(i,1,n)
    {
        j=read();
        if(i>=2)
        {
            if((ll)(j-k)*a>b)ans+=b;
            else ans+=(ll)(j-k)*a;
        }
        k=j;
    }
    printf("%lld\n",ans);
    //system("Pause");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define P pair<int,int>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define re(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007;
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int n,k,q;
    cin>>n>>k>>q;
    int a[q],b[n];
    rep(i,q){
        cin>>a[i];
    }
    rep(i,n){
        b[i]=k-q;
    }
    rep(i,q){
        b[a[i]-1]++;
    }
    rep(i,n){
        if(b[i]<=0){
            cout<<"No"<<endl;
        }
        else{
            cout<<"Yes"<<endl;
        }
    }
}

Measured memory_bytes: 2176
/**
 * Title: E - Red and Green Apples
 * Url: https://atcoder.jp/contests/abc160/tasks/abc160_e
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {

    int x, y, a, b, c; cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c);
    for(int i=0; i<a; i++) cin >> p[i];
    for(int i=0; i<b; i++) cin >> q[i];
    for(int i=0; i<c; i++) cin >> r[i];
    sort(p.begin(), p.end(), std::greater<int>());
    sort(q.begin(), q.end(), std::greater<int>());
    vector<ll> apples;
    for(int i=0; i<x; i++) {
        apples.push_back(p[i]);
    }
    for(int i=0; i<y; i++) {
        apples.push_back(q[i]);
    }
    for(int i=0; i<c; i++) {
        apples.push_back(r[i]);
    }
    sort(apples.begin(), apples.end(), std::greater<int>());
    ll ans = 0;
    for(int i=0; i<x+y; i++) ans += apples[i];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8816
#include<stdio.h>

int main(void)

{

int i,n;

int number;

long long int sum=0;

int min=0;

int max=0;

 

scanf("%d",&n);

 

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

{

scanf("%d",&number);

 

if(i==0)

{

min = number;

max = number;

}

if(number<min) min = number;

if(number>max) max = number;

 

sum += number;

}

 

printf("%d %d %lld\n",min,max,sum);

 

return 0;

}

Measured memory_bytes: 600
/*
    Mbak Sana Dong
*/
#include <bits/stdc++.h>
using namespace std;
#define long long int ll
int dp[200200];
int main()
{
    int n,m,i,j,k,x,y,ans,curr,temp;
    scanf("%d",&n);
    for(i=1;i<=n;i++) dp[i] = -1e9;
    dp[0] = 0;
    int maxi = -1;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&curr);
        dp[curr] = max(dp[curr], dp[curr-1] + 1);
        maxi = max(maxi, dp[curr]);
    }
    int sana = n - maxi;
    if(maxi < 0) sana = -1;
    printf("%d\n", sana);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin >> N >> M;
  
  int count[40] = {0};
  int K;
  int i,j;
  int A;
  for(i=0; i<N; i++){
    cin >> K;
    for(j=0; j<K; j++){
      cin >> A;
      count[A]++;
    }
  }
  
  int answer = 0;
  for(i=0; i<40; i++){
    if(count[i] == N)
      answer++;
  }
  
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;
    static int MOD = (int)1E9 + 7;
    public static void main(String[] args) {
        int H = ni();
        int W = ni();
        
        int count = 0;
        for (int h = 0; h < H; h++) {
            char[] cs = nsToChars();
            for (int w = 0; w < W; w++) {
                if (cs[w] == '#') count++;
            }
        }
        so.println(count == H+W-1 ? "Possible" : "Impossible");
    }

    private static long nl() {
        return sc.nextLong();
    }

    private static int ni() {
        return sc.nextInt();
    }

    private static String ns() {
        return sc.next();
    }

    private static char[] nsToChars() {
        return sc.next().toCharArray();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0);
    }
    private static int[] nints(int n) {
        return nints(n, 0);
    }

    private static long[] nlongs(int n, int offset) {
        long[] a = new long[offset + n];
        for (int i = 0; i < n; i++)
            a[offset + i] = nl();
        return a;
    }

    private static int[] nints(int n, int offset) {
        int[] a = new int[offset + n];
        for (int i = 0; i < n; i++)
            a[offset + i] = ni();
        return a;
    }
}


Measured memory_bytes: 23124
import java.util.*;

class Main{
    
   public static void main(String a[]) throws java.io.IOException{
       Scanner scan =new Scanner (System.in);
       boolean [] st =new boolean[31];
       st[0] = true;
       while(scan.hasNext())
           st[scan.nextInt()]=true;
       for(int i=0;i<31;i++)
           if(!st[i])
               System.out.println(i);
   }
}

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

int main() {
  int N;
  string S;
  cin>>N>>S;
  int mx=0;
  int x=0;
  rep(i,N){
    if(S[i]=='I')x++;
    else if(S[i]=='D')x--;
    mx = max(mx,x);
  }
  cout<<mx<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

int main()
{
    ll n;
    cin>>n;
    vector<ll> s(n);
    map<ll,ll>a;
    rep(i,n)
    {
        ll t;
        cin>>t;
        s[i]=t;
        a[t]++;
    }
    ll amount=0;
    for(auto itr=a.begin();itr!=a.end();itr++)
    {
        amount+=itr->second*(itr->second-1)/2;
    }
    rep(i,n)
    {
        if(a[s[i]]==2)
        {
            cout<<amount-1<<endl;
        }
        else if(a[s[i]]==1)
        {
            cout<<amount<<endl;
        }
        
        else
        {
            cout<<amount-(a[s[i]]-1)<<endl;
        }
        
    }

    
}

Measured memory_bytes: 12800
// Last Change: 04/13/2019 21:13:57.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

const char black = '0';
const char white = '1';

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

  const ll sSize = S.size();

  ll ans, tmpAns = 0;
  for (ll i = 0; i < sSize; ++i) {
    if (i % 2 == 0) {
      if (S[i] == black) {
        ++tmpAns;
      }
    } else {
      if (S[i] == white) {
        ++tmpAns;
      }
    }
  }
  ans = tmpAns;

  tmpAns = 0;
  for (ll i = 0; i < sSize; ++i) {
    if (i % 2 == 0) {
      if (S[i] == white) {
        ++tmpAns;
      }
    } else {
      if (S[i] == black) {
        ++tmpAns;
      }
    }
  }
  ans = min(ans, tmpAns);

  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 512
#include <stdio.h>

int main()
{
	int a,b,c,d,e;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	if(a==0) printf("1");
	else if(b==0) printf("2");
	else if(c==0) printf("3");
	else if(d==0) printf("4");
	else if(e==0) printf("5");
}

Measured memory_bytes: 1624
S = input()
N = len(S)
i = 0
s = []
while i < N:
    rc = lc = 0
    while i < N and S[i] == 'R':
        rc += 1
        i += 1
    while i < N and S[i] == 'L':
        lc += 1
        i += 1
    s.append((rc, lc))
ans = []
for R, L in s:
    r = (R+1) // 2 + L // 2
    l = R // 2 + (L+1) // 2
    ans.extend([0]*(R-1) + [r, l] + [0]*(L-1))
print(' '.join([str(x) for x in ans]))

Measured memory_bytes: 51796
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n; rd(n);
  auto s=new char[][](n);
  foreach(i; 0..n) s[i]=readln.chomp.to!(char[]);

  long[char] cnt;
  cnt['M']=cnt['A']=cnt['R']=cnt['C']=cnt['H']=0L;
  foreach(i; 0..n){
    auto c=s[i][0];
    if(c in cnt) cnt[c]++;
  }
  char[int] p;
  p[0]='M'; p[1]='A'; p[2]='R'; p[3]='C'; p[4]='H';

  long fun(int i, char[] h){
    if(h.length==3){
      long ret=1;
      foreach(c; h) ret*=cnt[c];
      return ret;
    }else if(i>=5){
      return 0L;
    }else{
      long ret=0;
      foreach(j; i..5)
        ret+=fun(j+1, h~p[j]);
      return ret;
    }
  }

  writeln(fun(0, []));
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

Measured memory_bytes: 7420
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int main() {
  int n,h,w;
  S(n); S(h); S(w);
  int ans = (n + 1 - h) * (n + 1 - w);
  P(ans);
  return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    sort(all(a));
    reverse(all(a));

    ll ans=a[0];
    int id=1;
    int cnt=0;
    for(int i=1;i<n-1;i++){
        if(cnt==0){
            cnt++;
            ans+=a[id];
        }
        else{
            cnt=0;
            ans+=a[id];
            id++;
        }
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const int INF = 1e9 +7;

int main(){
    int n;
    cin >> n;
    vector<double> v(n);
    REP(i, n){
        cin >> v[i];
    }

    sort(v.begin(), v.end());
    int ans = 0;
    double tmp = v[0];
    REP(i, n - 1){
        tmp = (tmp + v[i+1]) / 2;
    }

    cout << tmp << endl;
}

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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

    int t=1;
	//cin>>t;
	//SieveOfEratosthenes(1000000);
    while(t--){
        int n;
        cin>>n;
        map<int,int>m;
        for(int i=1;i<=100;i++){
            for(int j=1;j<=100;j++){
                for(int k=1;k<=100;k++){
                    m[i*i+j*j+k*k+i*j+j*k+k*i]++;
                }
            }
        }
        for(int i=1;i<=n;i++)
            cout<<m[i]<<'\n';
    }
}

Measured memory_bytes: 5420
#include <stdio.h>

int devide(int x, int y)
{
	if (y == 0)
	{
		return x;
	}
	else
	{
		return devide(y, x % y);
	}
}
int main()
{
    int num1, num2;
    int result;
    scanf(" %d %d",&num1,&num2);
    
    result = devide(num1,num2);
    printf("%d\n",result);
    
    return 0;
}


Measured memory_bytes: 2112
#include <iostream>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

int H, N, weight[1000], value[1000];
long long dp[1010][20010];

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

    for (int i = 0; i < 1010; ++i) {
      for (int j = 0; j < 20010; ++j) {
        dp[i][j] = INF;
      }
    }
    dp[0][0] = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= H + 10000; ++j) {
            // if (i < 10) cout << weight[i] << " " << value[i] << endl;
            if (j < weight[i]) {
              dp[i+1][j] = dp[i][j];
            } else {
              dp[i+1][j] = dp[i][j];
              if (dp[i+1][j] > dp[i + 1][j - weight[i]] + value[i]) {
                dp[i+1][j] = dp[i + 1][j - weight[i]] + value[i];
              }
            }
        }
    }

    long long res = INF;
    for (int j = H; j <= H + 10000; ++j) {
        long long cost = dp[N][j];
        if (cost < res) res = cost;
    }
    cout << res << endl;
}

Measured memory_bytes: 158080
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll N;
    cin >> N;
    vec dight;
    loop(i, 100)
    {
        ll x = pow(2, i + 1);
        ll y = pow(2, i);
        if (N % x > 0 || N % x < 0)
        {
            dight.push_back(1);
            if (i % 2 == 0)
                N -= y;
            else
                N += y;
        }
        else
            dight.push_back(0);
        if (N == 0)
            break;
    }
    ll siz = dight.size();
    loop(i, siz) cout << dight[siz - 1 - i];
    putout("");
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    int n=s.length();
    int i=0;
    int check=0;

    while(1){
        if(s[i]==s[i+1]){
            check=1;
            break;
        }
        if(s[i]==s[i+2]){
            check=2;
            break;
        }
        i++;
        if(i==n) break;
    }

    if(check==0){
        cout << -1 << ' ' << -1 << endl;
    }
    else if(check==1){
        cout << i+1 << ' ' << i+2 << endl;
    }
    else{
        cout << i+1 << ' ' << i+3 << endl;
    }

    return 0;
}

Measured memory_bytes: 3708
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = unsigned long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
int const mod = 1e9+7;
#define END {cout<<(ans)<<'\n'; return 0;}
#define ALL(vec) vec.begin(),vec.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,s,n) for(int i=s; i<n; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,(n)-1)cout<<a[i]<<' '; cout<<a[(n)-1]<<'\n';
#define prip(p) cout<<(p).first<<' '<<(p).second<<'\n'
template<class T> inline bool cmin(T& a, T b) { if (a > b) { return a = b; } return false; }
template<class T> inline bool cmax(T& a, T b) { if (a < b) { return a = b; } return false; }

int n,m,q,_,x,y;
string s,sb;
bool ok;
char ch;

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

  cin>>n; unordered_map<string,bool>a;
  rep(i,n){
    cin>>sb>>s;
    if(sb=="insert")a[s]=1;
    else cout<<(a[s]?"yes":"no")<<'\n';
  }
}


Measured memory_bytes: 45656
use std::io::Read;

fn main() {
    let (x, y, z) = input();
    let ans = solve(x, y, z);
    println!("{} {} {}", ans.0, ans.1, ans.2);
}

fn input() -> (u32, u32, u32) {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    buf.pop();
    let mut iter = buf.split_whitespace();
    let x: u32 = iter.next().unwrap().parse().unwrap();
    let y: u32 = iter.next().unwrap().parse().unwrap();
    let z: u32 = iter.next().unwrap().parse().unwrap();
    (x, y, z)
}

fn solve(x: u32, y: u32, z: u32) -> (u32, u32, u32) {
    (z, x, y)
}


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

int main() {
  int N, K = -1;
  cin >> N;
  for (int i = 2; i <= 500; i++) {
    if (i * (i - 1) == 2 * N) {
      K = i;
      break;
    }
  }
  if (K == -1) cout << "No" << endl;
  else {
    cout << "Yes" << endl;
    cout << K << endl;
    vector<vector<int>> V(K);
    int x = 0;
    for (int i = 0; i < K; i++) {
      for (int j = i + 1; j < K; j++) {
        x++;
        V.at(i).push_back(x);
        V.at(j).push_back(x);
      }
    }
    for (int i = 0; i < K; i++) {
      cout << K - 1 << " ";
      for (int j = 0; j < K - 1; j++) {
        cout << V.at(i).at(j) << " ";
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 4264
# coding: utf-8
N=int(input())
S=list(input())

l=0
r=0
pl=0
pr=0


for i in range(N):
    if S[i]==")":
        r+=1
        if pl+l<r:
            pl+=1
        else:
            pr-=1
    else:
        l+=1
        pr+=1

sl=["(" for i in range(pl)]
sr=[")" for i in range(pr)]

ans=sl + S + sr

print("".join(ans))

Measured memory_bytes: 3064
#include <ext/pb_ds/assoc_container.hpp>
  #include <bits/stdc++.h>
  using namespace std;
  using namespace __gnu_pbds;
  template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
  #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  #define TRACE
  #ifdef TRACE
  #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
  template <typename Arg1>
  void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
  }
  template <typename Arg1, typename... Args>
  void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
  }
  #else
  #define trace(...) 
  #endif
  template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
  template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
  template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
  typedef long long int ll;
  const ll mod =1e18;
  const int maxn = 300002;
  #define endl '\n'
  #define int ll
  #define ld long double
  #define all(x) (x).begin(),(x).end()


  int32_t main()
  { 
    IOS
   
    string s;
    cin>>s;
    int n = s.size();
    int k ;
    cin>>k;
    for(int i = 0;i<n;i+=k){
      cout<<s[i];
    }



    
    

    

    
    
    
  }

Measured memory_bytes: 3580
use proconio::{fastout, input};

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

    if n < 3 {
        println!("{}", 0);
        return;
    }

    l.sort();

    let mut ans = 0;
    for i in 0..(n - 2) {
        for j in (i + 1)..(n - 1) {
            for k in (j + 1)..n {
                // if l[i] + l[j] > l[k] && l[i] != l[j] && l[j] != l[k] && l[k] != l[i] {
                //     ans += 1;
                // }
                if l[i] == l[j] || l[j] == l[k] || l[k] == l[i] {
                    continue;
                }
                if l[k] < l[i] + l[j] && l[i] < l[j] + l[k] && l[j] < l[k] + l[i] {
                    ans += 1;
                }
            }
        }
    }

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


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

int main()
{
	string s,t,ans;
	cin>>s;
	cin>>t;
	
	ll len1=s.length();
	ll len2=t.length();
	
	ll dp[len1+1][len2+1];
	
	for(ll i=0;i<=len1;i++)
	{
		for(ll j=0;j<=len2;j++)
		{
			if(i==0||j==0)
			{
				dp[i][j]=0;
			}
			else
			{
			
			if(s[i-1]==t[j-1])
			{
				dp[i][j]=1+dp[i-1][j-1];
			}
			
			else
			{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		    }
		}
	}
	
	// printing lcs
	ll a,b;
	a=len1;b=len2;
	while(a>0&&b>0)
	{
	if(s[a-1]==t[b-1])
	{
		ans.push_back(s[a-1]);
		a=a-1;
		b=b-1;
		}
		
	else if(dp[a-1][b]>dp[a][b-1])
		{
			a=a-1;
			}	
			
			else
			{
				b=b-1;
			}
			
			
	}
	
	for(ll i=dp[len1][len2]-1;i>=0;i--)
	{
		cout<<ans[i];
	}
	cout<<endl;
	
	
	
}
 


Measured memory_bytes: 70656
# AB -> BBAA -> BAAAA -> BA
# Thus, this problem has commutative property.
# So, if we let A and B satisfy x^2 + x + 1 == 0,
# then A^2 == B, B^2 == A, and A^3 == B^3 == 1.
# So this makes an invariant.

from itertools import accumulate

S = input()
T = input()
q = int(input())
abcds = [tuple(map(int, input().split())) for _ in range(q)]

S_csum = list(map(lambda x: x%3, accumulate(map(lambda c: 1 if c == 'A' else -1, S), initial=0)))
T_csum = list(map(lambda x: x%3, accumulate(map(lambda c: 1 if c == 'A' else -1, T), initial=0)))

for a, b, c, d in abcds:
    if (S_csum[b] - S_csum[a-1]) % 3 == (T_csum[d] - T_csum[c-1]) % 3:
        print("YES")
    else:
        print("NO")

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

int main(void) {
  int H, W;
  cin >> H >> W;
  char s[H][W];
  for(auto& x : s) {
    for(auto& cell : x) {
      cin >> cell;
    }
  }

  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(s[i][j] == '#') {
        if(i > 0 && s[i-1][j] == '#') continue;
        if(j > 0 && s[i][j-1] == '#') continue;
        if(i < H-1 && s[i+1][j] == '#') continue;
        if(j < W-1 && s[i][j+1] == '#') continue;
        //can't draw
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
n, x, y = gets.chomp.split.map(&:to_i)
xs = gets.chomp.split.map(&:to_i)

if n == 1
  p (xs[0] - y).abs
  exit
end

cs = []
cs << (xs[n-1] - y).abs
cs << (xs[n-2] - xs[n-1]).abs
p cs.max


Measured memory_bytes: 1916
#include <iostream>
#include <set>

using namespace std;

int main () {
  long long n;
  cin >> n;
  cin.ignore ();
  set<string> st;
  string s;
  while (n--) {
    getline (cin, s);
    st.insert (s);
  }
  cout << st.size () << '\n';
  return 0;
}
  

Measured memory_bytes: 19228
#include<stdio.h>
int main(void){
  int A,B,C,D;
  scanf("%d %d %d %d",&A,&B,&C,&D);
  if(1>A || 100<A || 1>B || 100<B || 1>C || 100<C || 1>D|| 100<D){
    printf("input error");
    return 0;
  }
  do{
    C = C-B;
    A = A-D;
  }while(C>0 && A>0);
  if(C<=0){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 1732
R, C = list(map(int, input().split()))
sy, sx = 2, 2
gy, gx = R, C

meiro = ["#" + input() + "#" for _ in range(R)]
meiro = ["#"*(C+2)] + meiro + ["#"*(C+2)]

kyori = [[int(0) for x in range(C+2)] for _ in range(R+2)]
kyori[sy-1][sx-1] = 0

visited = [[sy-1,sx-1]]
que = [[sy-1,sx-1]]

while True:
    x = que[0][1]
    y = que[0][0]
    que.pop(0)
    try:
        if meiro[y][x+1] == "." and [y,x+1] not in visited:
            que.append([y,x+1])
            visited.append([y,x+1])
            kyori[y][x+1] = kyori[y][x] + 1
        if meiro[y+1][x] == "." and [y+1,x] not in visited:
            que.append([y+1,x])
            visited.append([y+1,x])
            kyori[y+1][x] = kyori[y][x] + 1
        if meiro[y][x-1] == "." and [y,x-1] not in visited:
            que.append([y,x-1])
            visited.append([y,x-1])
            kyori[y][x-1] = kyori[y][x] + 1
        if meiro[y-1][x] == "." and [y-1,x] not in visited:
            que.append([y-1,x])
            visited.append([y-1,x])
            kyori[y-1][x] = kyori[y][x] + 1
    except:
        IndexError
    if que == []:
        break

if kyori[R][C] == 0:
    print(-1)
    exit(0)

t = 0
for k in range(1,R+1):
    t += meiro[k].count("#")-2

print(R*C-kyori[R][C]-t-1)

Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
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;
}
using namespace std;


void solve(){
    int x;
    cin>>x;
    int a=(x+104)/105;
    int s=a*100;
    int t=a*105;
    if(x>=s&&x<=t)cout<<1<<"\n";
    else cout<<0<<endl;
}
 
int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 256
N, A = map(int, input().split())
x = [int(i) for i in input().split()]

ax = [i - A for i in x]
p, m = 0, 0

for i in ax :
    if i > 0 :
        p += i
    else :
        m -= i

dp = [[0] * (p + m + 1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(N) :
    for j in range(p + m + 1) :
        dp[i+1][(j+ax[i])%(p+m+1)] += dp[i][j]
        dp[i+1][j] += dp[i][j]

print(dp[N][0]-1)        

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

//________
typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
typedef vector<Pii> Vp;
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define All(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define show(x) cerr << #x << ':' << x << endl
#define outl(x) cout << x << '\n';

#define INF (1 << 29)

#define FAST cin.tie(0), ios::sync_with_stdio(false)
inline int chmax(int &a, int b){return b>a ? a=b,1 : 0;}
inline int chmin(int &a, int b){return b<a ? a=b,1 : 0;}
//________

ll mem[100];

ll luca(int n){
	if(n == 0)return 2;
	if(n == 1)return n;
	if(mem[n] != 0)return mem[n];
	return mem[n] = luca(n-1) + luca(n-2);
}

main(){
	FAST;
	int n;
	cin >> n;
	outl(luca(n));
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    // Your code here!
    int m,f,r,k;
    
    while(1){
        cin>>m>>f>>r;
        k=m+f;
        if(m==-1 && f==-1 && r==-1) break;
        
        if(m==-1 || f==-1) cout<<'F'<<endl;
        else if(k>=80) cout<<'A'<<endl;
        else if(65<=k)   cout<<'B'<<endl;
        else if(50<=k)   cout<<'C'<<endl;
        else if(30<=k){
            if(r>=50)
                cout<<'C'<<endl;
            else
                cout<<'D'<<endl;
        }
        else if (k<30) cout<<'F'<<endl;

    }
    return 0;
}



Measured memory_bytes: 3080
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;

ll N, M;
ll a[100010], two[100010], twoL;
bool fl = true;

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

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

int main()
{
  std::cin >> N >> M;

  rep( i, N )
    std::cin >> a[i], fl &= a[i]%2 == 0;

  if( !fl )
  {
    std::cout << 0 << std::endl;

    return 0;
  }

  ll ma = 0;

  rep( i, N )
  {
    a[i] -= a[i]/2;

    ll A = a[i];

    while( A % 2 == 0 )
      A /= 2, ++two[i]; 

    ma = std::max( ma, two[i] );
  }

  rep( i, N ) if( ma != two[i] )
  {
    std::cout << 0 << std::endl;

    return 0;
  }

  ll L = 1;

  rep( i, N )
    L = lcm(L, a[i]);

  ll cnt = M/L;

  std::cout << cnt-cnt/2 << std::endl;

  return 0;
}

Measured memory_bytes: 1792