akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

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

		long N = Long.parseLong(sc.next());

		sc.close();

		for (long i = (long) Math.sqrt(N); i >= 1; i--) {
			if (N % i == 0) {
//				System.out.println(i);
//				System.out.println(N / i);
				System.out.println(i - 1 + N / i - 1);
				break;
			}
		}

	}
}


Measured memory_bytes: 23124
n, t = map(int, input().split())
l = list(map(int, input().split()))
l_sa = []
for i in range(n - 1):
    l_sa.append(l[i + 1] - l[i])
for i in range(n - 1):
    if l_sa[i] > t:
        l_sa[i] = t
print(sum(l_sa) + t)


Measured memory_bytes: 25200
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j,k;
  int a[100],m,n;
  int sm;
  char s[100][9],t[1000][9];
  while(cin>>n>>m&&n+m){
    for(i=0;i<n;i++)
      cin>>s[i]>>a[i];
    for(i=0;i<m;i++)
      cin>>t[i];
    sm=0;
    for(j=0;j<m;j++){
      for(i=0;i<n;i++){
	for(k=0;k<8;k++){
	  if(s[i][k]!='*'&&s[i][k]!=t[j][k])
	    break;
	}
	if(k==8){
	  sm+=a[i];
	  break;
	}
      }
    }
    cout<<sm<<endl;
  }
  return 0;
}

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

int main() {
  
  int a,b;
  cin >> a >> b;
  
  if(a <= b) cout << "unsafe" << endl;
  else cout << "safe" << endl;
  
}


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

int main(void){
    string s; cin >> s;
    int a,b,c,d;
    a=stoi(s.substr(0,1));
    b=stoi(s.substr(1,1));
    c=stoi(s.substr(2,1));
    d=stoi(s.substr(3,1));
    int A[3]; A[0]=b; A[1]=c; A[2]=d;
    for(int i=0; i<8; i++){
        string ans="";
        ans+=to_string(a);
        int value=a;
        for(int j=0; j<3; j++){

            if((i&(1<<j))){
                ans+='+';
                value+=A[j];
            }
            else{
                ans+='-';
                value-=A[j];
            }
            ans+=to_string(A[j]);

        }

        if(value==7){
            ans+="=7";
            cout << ans << endl;
            return 0;
        }
    }
    
}

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

int main()
{
int i;
int j;
int N;
int M;
int X;
int A[ 110 ];

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;
	cin >> M;
	cin >> X;

	for( i = 0; i < M; i++ ) cin >> A[ i ];

auto a = lower_bound( &A[ 0 ], &A[ M ], X );

	i = a - &A[ 0 ];
	j = &A[ M ] - a;

	if( i > j )
		cout << j << endl;
	else
		cout << i << endl;

	return 0;
}






Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)
#define in(a) scanf("%lld", &(a))
#define in2(a,b) scanf("%lld %lld",&(a),&(b))
#define in3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
#define ind(a) scanf("%lf", &(a))
#define ins(a) scanf("%s", (a))
#define inc(a) scanf("%c", &(a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a))
//      puts(a) printf("%s\n", a) 文字はこっち
//your code here!
int main(void){
    ll X;
    in(X);
    for(ll i=1; ; i++){
        if(i*(i+1)/2>=X){
            put(i);
            return 0;
        }
    }
}


Measured memory_bytes: 128
#include<stdio.h>
int main (void){
    int x1=0,x2=0,x3=0,input,s;
    for(s=0;s<10;s++){
        scanf("%d\n",&input);
        if(x1 < input){
            x3 = x2;
            x2 = x1;
            x1 = input;
        }else{
            if(x2 < input){
                x3 = x2;
                x2 = input;
            }else{
                if(x3 < input){
                    x3 = input;
                }
            }
        }
    }
    printf("%d\n%d\n%d\n",x1,x2,x3);
    return(0);
}

Measured memory_bytes: 604
n,m,x=map(int,input().split())
ca=[]
ans=float('inf')
for _ in range(n):
    ca.append(list(map(int,input().split())))
for i in range(2**n):
    money=0
    check=[0]*(m)
    for j in range(n):
        if ((i>>j)&1):
            money+=ca[j][0]
            for k in range(m):
                check[k]+=ca[j][k+1]
    if all(check[p]>=x for p in range(m)):
        ans=min(ans,money)
if ans==float('inf'):
    print('-1')
else:
    print(ans)

Measured memory_bytes: 9228
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        StringBuilder sba = new StringBuilder();
        StringBuilder sbb = new StringBuilder();
        for (int i = 0; i < b; i++) {
            sba.append(a);
        }
        for (int i = 0; i < a; i++) {
            sbb.append(b);
        }

        System.out.println(compareStr(sba.toString(), sbb.toString()));
        sc.close();
    }

    private static String compareStr(String a, String b) {
        int i = a.compareTo(b);
        if (i <= -1) {
            return a;
        }
        if (i >= 1) {
            return b;
        } else {
            return a;
        }
    }
}


Measured memory_bytes: 35480
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod = 10e9+7;

#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prtd(n, var)  cout << fixed << setprecision(n) << var << endl
#define prt2(var1, var2) cout << var1 << " " << var2 << endl

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

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

  if(a>12){
    prt(b);
  } else if (a<6){
    prt(0);
  } else {
    prt(b/2);
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second

#define END puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();

int main() {
    clue();
    return 0;
}
int clue() {

    int n,x,t;
    cin>>n>>x>>t;
    double c=ceil(n/(x*1.0));
    lli p=c*t;
    cout<<p<<endl;
    return 0;
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int S,a,b,c,d;
  cin >> S;
  a=S-S%1000; //1000
  b=S-a-S%100;  //100
  c=S-a-b-S%10;
  d=S-a-b-c;


  if(a!=b*10){
    if(b!=c*10){
      if(c!=d*10){
        cout << "Good" << endl; 
      }
      else{
        cout << "Bad" << endl; 
      }
    }
    else{
      cout << "Bad" << endl; 
    }
  }
  else{
    cout << "Bad" << endl; 
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) {rep(i,x.size()) cout << x[i] << " "; cout << endl;}
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9+7;
const ll inf_l = 1e18;
const int MAX = 1e6;

int main() {
    int n, m, k; cin >> n >> m >> k;
    vll a(n+1,0), b(m+1,0);
    rep(i,n) {
        ll x; cin >> x;
        a[i+1] = a[i] + x;
    }
    rep(i,m) {
        ll x; cin >> x;
        b[i+1] = b[i] + x;
    }
    int ans = 0;
    rep(i,n+1) {
        ll rem = k - a[i];
        if (rem < 0) continue;
        int x = upper_bound(all(b),rem) - b.begin();
        ans = max(ans,i+x-1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;

ll ans;
int main()
{
    ll n,k;
    cin>>n>>k;
    for(ll i=k;i<=n+1;i++)
    {
    	ans%=mod;
        ans+=i*(2*n+1-i)/2-i*(i-1)/2+1;
        ans%=mod;
    }
    cout<<ans%mod<<endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<int> A(N);
    for(int i=0;i<N;i++) cin >> A[i];

    bool ok = true;
    for(int i=0;i<N-1;i++) ok &= A[i]<A[i+1];
    if(ok){
        cout << 1 << endl;
        return 0;
    }
    
    auto valid = [&](int x){
        map<int,int> mp;
        for(int i=1;i<N;i++){
            if(A[i-1]<A[i]) continue;
            map<int,int>::iterator it = mp.begin();
            while(it!=mp.end() && -it->first>A[i]) it = mp.erase(it);
            if(it==mp.end() || -it->first<A[i]){
                mp[-A[i]] = 2;
                continue;
            }
            assert(-it->first==A[i]);
            if(it->second!=x){
                it->second++;
                continue;
            }
            while(it!=mp.end()){
                int val = -it->first;
                assert(it->second==x);
                it = mp.erase(it);
                if(it==mp.end()){
                    if(val==1) return false;
                    else{
                        mp[-(val-1)] = 2;
                        break;
                    }
                }else{
                    if(-it->first!=val-1){
                        mp[-(val-1)] = 2;
                        break;
                    }
                    if(it->second!=x){
                        it->second++;
                        break;
                    }
                }
            }
        }
        return true;
    };

    int l = 1,r = N;
    while(l+1<r){
        int m = (l+r)>>1;
        (valid(m)? r:l) = m;
    }
    cout << r << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
long long a[200000];
int main(){
    int n;
    long long b, sum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%lld",&a[i]);
    for(int i=0;i<n;i++)a[i]-=i;
    std::sort(a,a+n);
    b=a[n/2];
    for(int i=0;i<n;i++)sum+=std::abs(a[i]-b);
    printf("%lld",sum);
    return 0;
}

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

using namespace std;

#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'

int n;
int a[50];

int main()
{
	IOS;
	cin >> n;
	int c = 0;
	for (int i = 0; i < n; i++) 
		cin >> a[i];
	for (int i = 1; i < n-1; i++) {
		if ((a[i] > a[i-1] && a[i] < a[i+1]) || (a[i] < a[i-1] && a[i] > a[i+1]))
			c++;
	}
	cout << c << endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    if((a+b) > (c+d)){
      System.out.println("Left");
    }else if((a+b) < (c+d)){
      System.out.println("Right");
    }else if((a+b) == (c+d)){
      System.out.println("Balanced");
    }
  }
}

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

struct node{
  int key;
  struct node *right;
  struct node *left;
  struct node *parent;
};

typedef struct node * Node;
#define NIL NULL

Node root;


Node treeSearch(Node ,int);
void print(Node );
void preorder(Node );
void inorder(Node );
void insert(int);
void treeDelete(Node);
Node treeSuccessor(Node);
Node treeMinimum(Node);
int main(){
  int n;
  int  i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
  
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      
       Node t = treeSearch(root, x);      
       if ( t != NIL ) printf("yes\n");
       else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}


void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent = y;   
  if(y == NIL) {
    root = z; //Tが空
  }
  else if(z->key < y->key ){
    y->left = z;
  }
  else y->right = z;
}

void print(Node root){
  inorder(root);
  preorder(root);
}

void preorder(Node u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

Node treeSearch(Node u,int k){
  int i;
  while(u != NIL){
    if(u->key == k) return u;
    if(k< u->key ) u = u->left;
    else u = u->right; 
  }
  return NIL;
}

void treeDelete(Node u){
  Node y; // node to be deleted
  Node x; // child of y

  if(u->left == NIL || u->right == NIL){
    y = u;
  }
  else
    y = treeSuccessor(u);

  if(y->left != NIL){
    x = y->left;
  }
  else{
    x = y->right;
  }

  if(x != NIL){
    x->parent =  y->parent;
  }
  if(y->parent == NIL){
    root = x;
  }
  else if(y == y->parent->left){
    y->parent->left = x;
  }
  else{
    y->parent->right = x;
  }

  if(y != u){
    u->key = y->key; 
  }

}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL){
    return treeMinimum(x->right);
  }

  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}


Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}



Measured memory_bytes: 20448
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=405;
const int mod=998244353;
int n,inv[N],f[N][N],g[N],sa,sb,ans;
void Inc(int &x,int y){
	x+=y;x>=mod?x-=mod:x;
}
int main(){
	scanf("%d",&n);
	f[0][0]=mod-1;g[0]=inv[1]=1;
	for(int i=2;i<N;++i)
		inv[i]=1ll*inv[mod%i]*(mod-mod/i)%mod;
	for(int i=1,a,b;i<=n;++i){
		scanf("%d%d",&a,&b);
		for(int j=1;j<b;++j)
			g[j]=1ll*g[j-1]*a%mod*inv[j]%mod;
		for(int j=sa;~j;--j)
			for(int k=0;k<=sb;++k)
				for(int l=0;l<b;++l)
					Inc(f[j+a][k+l],mod-1ll*f[j][k]*g[l]%mod);
		sa+=a;sb+=b-1;
	}
	for(int i=1;i<=sa;++i)
		for(int j=0,k=inv[i];j<=sb;++j,k=1ll*k*inv[i]%mod*j%mod)
			Inc(ans,1ll*f[i][j]*k%mod);
	ans=1ll*ans*sa%mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 768
t = input()
a = int(t)
d = ['+','-']
for i in range(2**3):
	S = a//1000
	ans = t[0]
	for j in range(3):
		S += int(d[(i>>j&1)]+t[j+1])
		ans+= d[(i>>j&1)]+t[j+1]
	#print(S,ans)
	if S == 7:
		print(ans+'=7')
		exit()
		


Measured memory_bytes: 3060
#include<stdio.h>
int gcd(int a, int b)
{
	if (a%b == 0)
		return b;
	else
		return gcd(b, a%b);
}

int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	printf("%d\n", gcd(a, b));
	return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
#define nl                 "\n"
#define ll                 long long
#define pb                 push_back
#define pf                 push_front
#define np                 next_permutation
#define pp                 prev_permutation
#define sqr(x)             ((x)*(x))
#define pi                 acos(-1)
#define setprecision(x)    fixed<<setprecision((int)(x))
#define mem1(x)            memset(x,0,sizeof(x))
#define mem2(x)            memset(x,-1,sizeof(x))
#define all(x)             (x).begin(),(x).end()
#define rev(x)             reverse(all(x))
#define iota(x,a)          iota(all(x),a)
#define sorta(x)           sort(all(x))
#define sortd(x)           sort(all(x),greater<int>())
#define csort(x,c)         sort(all(x),c)
#define rsort(x)           sort(x.rbegin(),x.rend())
#define faster_io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define all_ele(x)         for(auto i:(x)){cout<<i<<' ';}cout<<nl;
#define multiple_test      int t; cin>>t; while(t--){solve();}
#define single_test        solve();
using namespace std;
//vector<vector<int>>p(sz,vector<int>(sz,val));
void solve()
{
   ll n;
   cin>>n;
   vector<ll>a(n);
   for(int i=0; i<n; i++)
        cin>>a[i];
   ll thaka=1000;
   for(int i=0; i<n-1; i++)
   {
       ll bundle=0;
       if(a[i]<a[i+1])
          {
              bundle=thaka/a[i];
              thaka=thaka%a[i];
              thaka+=(bundle*a[i+1]);
          }
   }
   cout<<thaka<<nl;
}
int main()
{
    faster_io;
    //multiple_test
    single_test
    return 0;
}




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

#define int long long

int ans(int l,int b,int h){
    if (l%2==0 || b%2==0 || h%2==0){
        return(0);
    }
    if(l%2==1 & b%2==1 & h%2==1){
        int multi[3];
        int lb = l*b;
        int bh = b*h;
        int lh = l*h;
        multi[0] = lb;
        multi[1] = bh;
        multi[2] = lh;
        int k = sizeof(multi)/sizeof(multi[0]);
        sort(multi, multi+k);
        return(multi[0]);
    }
}

signed main(){
    int a,b,c;
    cin >> a;
    cin >> b;
    cin >> c;
    cout << ans(a,b,c);
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    int ans = 0;
    rep(i, k) ans += a[i];
    cout << ans << endl;
}

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

using namespace std;

int cnt[300000];

int main () {

        int n, k;

        scanf("%d %d", &n, &k);

        for (int i = 0; i < n; i++) {
                int a;
                scanf("%d", &a);
                a--;
                cnt[a]++;
        }
        sort(cnt, cnt + n);

        int res = 0;
        for (int i = 0; i < n - k; i++) {
                res += cnt[i];
                //printf("%d\n", cnt[i]);
        }
        printf("%d\n", res);

        return 0;

}


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

bool comp (int a, int b) {
    return a>b;
}

void solve() {
    int n,k;
    cin >> n >> k;
    vector <int> h(n);
    for(int i=0;i<n;i++)
        cin >> h[i];
    long long sum = 0;
    sort(h.begin(),h.end(),comp);
    if(k>n) {
        cout << "0" <<endl;
        return;
    }
    else {
        for(int i = 0;i < n; i++) {
            if(i>=k) {
                sum += h[i];
            }
        }
    }
    cout << sum << endl;
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(0);
    // freopen("a.txt","r",stdin);
    solve();
    return 0;
}

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

int main(){
	int H,W;
	cin>>H>>W;
	char s[H+2][W+2];
	for(int i=0;i<=H+1;++i){
		for(int j=0;j<=W+1;++j){
			if(i==0 || j==0 || i==H+1 || j==W+1)s[i][j]='+';
			else cin>>s[i][j];
		}
	}
	/*
	for(int i=0;i<=H+1;++i){
		for(int j=0;j<=W+1;++j){
			cout<<s[i][j]<<" ";
		}
		cout<<endl;
	}
	*/
	cout<<endl;
	bool ans=true;
	for(int i=1;i<=H;++i){
		for(int j=1;j<=W;++j){
			if(s[i][j]=='#'){
				if(s[i+1][j]!='#' && s[i][j+1]!='#' && s[i-1][j]!='#' && s[i][j-1]!='#')ans=false;
			}
		}
	}
	if(ans==true)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1e9;
const int MAX_N = 100010;

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

    vector<vector<int>> G(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].push_back(b);
    }

    int sv, tv;
    cin >> sv >> tv;
    sv--;  tv--;

    vector<vector<int>> dist(MAX_N, vector<int>(3, INF));
    queue<pair<int, int>> Q;

    Q.push(make_pair(sv, 0));
    dist[sv][0] = 0;
    while(!Q.empty()) {
        int v = Q.front().first;
        int L = Q.front().second;
        Q.pop();
        for(auto u : G[v]) {
            int nL = (L+1)%3;
            if(dist[u][nL] != INF) {
                continue;
            }
            dist[u][nL] = dist[v][L] + 1;
            Q.push(make_pair(u, nL));
        }
    }
    
    int ans = dist[tv][0];
    if(ans == INF) {
        ans = -1;
    }
    else {
        ans /= 3;
    }

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

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef deque<int> DI;
typedef deque<LL> DLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

LL modpow(LL a, LL n, LL m) {
	if(n == 0)	return 1;
	if(n == 1)	return a%m;
	if(n == 2)	return (a*a)%m;
	LL res = 1;
	while(n != 0) {
		if(n%2 == 1)	res = (res*a)%m;
		n >>= 1;
		a = (a*a)%m;
	}
	return res;
}

LL modinv(LL a, LL m) {
	return modpow(a, m-2, m);
}

LL modnCr(LL n, LL r, LL m) {
	assert(r <= 2e5+10);
	LL num = 1, den = 1;
	rep(i, n-r+1, n+1)	num = (num * i) % m;
	rep(i, 1, r+1)	den = (den * i) % m;
	LL ans = ( num * modinv(den, m) ) % m;
	return ans;
}

int main() {
	sll(n); sll(a); sll(b);
	// sum of nCr from r = 1 to n except r = a and r = b
	LL ans = (modpow(2, n, MOD) - modnCr(n, a, MOD) - modnCr(n, b, MOD) - 1) % MOD;
	while(ans < 0)	ans += MOD;
	ans %= MOD;
	pll(ans); nl;
}


Measured memory_bytes: 256
from collections import defaultdict
n, W = map(int, input().split())
dd = defaultdict(list)
for i in range(n):
    weight, value = map(int, input().split())
    dd[weight].append(value)

for k in dd.keys():
    dd[k].sort(reverse=True)

a = min(dd.keys())
b, c, d = a+1, a+2, a+3
ans = 0
for w in range(len(dd[a])+1):
    for x in range(len(dd[b])+1):
        for y in range(len(dd[c])+1):
            for z in range(len(dd[d])+1):
                if W < a*w+b*x+c*y+d*z:
                    continue
                val = sum(dd[a][:w])+sum(dd[b][:x]) + \
                    sum(dd[c][:y])+sum(dd[d][:z])
                ans = max(ans, val)
print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
using namespace std;

#define ll long long
#define ull unsigned long long
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

//sort(arr, arr+n, greater<int>())

//for(int i = 0; i < size; i++)
//    cout << a[i] << " ";

map <char, int> s;
map<char, int>::iterator it;

int main()
{
    fast_io;

    string a;
    bool flag = 0;

    cin >> a;

    for(int i = 0; i < a.size(); i++)
    {
        if(s.find(a[i]) == s.end())
        {
            s[a[i]] = 1;
        }

        else
        {
            it = s.find(a[i]);
            it->second++;
        }
    }

    for(it = s.begin(); it != s.end(); it++)
    {
        if(!(it->second & 1)) continue;
        else
        {
            flag = 1;
            break;
        }
    }

    if(flag == 0) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 3668
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = list(map(int, input().split()))
    #a = [list(input().split()) for i in range(n)]
    #a = [int(input()) for i in range(n)]
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    s=int(input())
    print((s//500)*1000+((s-(((s//500)*500)))//5)*5)

if __name__ == '__main__':
    main()



Measured memory_bytes: 38256
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP
*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define PB push_back
#define IN insert
#define MP make_pair
#define LW(v) sort(v.begin(),v.end());
#define HI(v) sort(v.begin(),v.end(),greater<long long>());
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>n>>m;
    if(n<10)
    {
        m=m+(100*(10-n));
    }
    cout<<m<<endl;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> sunuke(N,1);
  int d,A;
  for(int i=0;i<K;i++){
    cin >> d;
    for(int j=0;j<d;j++){
      cin >> A;
      sunuke.at(A-1)=0;
    }
  }

  int ans=0;
  for(int i=0;i<N;i++){
    if(sunuke.at(i)==1) ans++;
  }

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


Measured memory_bytes: 3636
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

int main()
{
    int m, d;
    std::string str;
    std::cin >> m >> d;

    int ans = 0;

    for (int i = 1; i <= m; i++)
    {
        for (int j = 22; j <= d; j++)
        {
            str = std::to_string(j);
            if (str[1] - '0' >= 2)
            {
                if ((str[0] - '0') * (str[1] - '0') == i)
                {
                    ans++;
                }
            }
        }
    }
    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
'use strict'

const main = (input) => {
    const num = parseInt(input.split('\n')[0])
    for(let i = num; i <= 999; i++){
        if(i % 111 === 0){
            console.log(i)
            break;
        }
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 7500
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <string>

using namespace std;

void solve();

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

void solve() {
    int H,W;
    cin >> H >> W;
    char map[H][W];
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cin >> map[i][j];
        }
    }
    int X[H];
    int XX[H];

    for(int i = 0; i < H; i++) {
        X[i] = 0;
        XX[i] = 0;
        for(int j = 0; j < W; j++) {
            if(map[i][j] == '#') X[i] = j;
        }
        for(int j = W-1; j >= 0; j--) {
            if(map[i][j] == '#') XX[i] = j;
        }
    }
    bool ok = true;
    for(int i = 1; i < H; i++) {
        if(X[i-1] <= X[i]) ok = true;
        else {
            ok = false;
            break;
        }
        if(XX[i] >= X[i-1]) ok = true;
        else {
            ok = false;
            break;
        }
    }
    if(ok) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }

    
}

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

using namespace std;

typedef long long int ll;

const int N = 1e5 + 10, MOD = 998244353;

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

ll n, m;
char c[N], d[N];
map<ll, char> mp;

int main() {
	scanf("%lld%lld%s%s", &n, &m, &c, &d);
	ll lcm = (ll) n * m / (gcd(n, m));
	string s = c, t = d;
	ll inc1 = lcm / n;
	for (int i = 0; i < n; i++) {
		mp[i * inc1] = c[i];
	}
	ll inc2 = lcm / m;
	for (int i = 0; i < m; i++) {
		if (mp[i * inc2] != d[i] && mp[i * inc2] >= 'a' && mp[i * inc2] <= 'z')
			return printf("-1"), 0;
	}
	printf("%lld\n", lcm);
	return 0;
}


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

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

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int H,W,D; cin >> H >> W >> D;
    int A[H][W];
    vector<P> num2xy(H*W+1);
    REP(i,H)REP(j,W){
        cin >> A[i][j];
        num2xy[--A[i][j]] = MP(i,j);
    }

    VVI dist(D);
    REP(i,D){
        dist[i].push_back(0);
        int j = i;
        auto p = num2xy[j]; int pre_x = p.first, pre_y = p.second;
        j += D;
        while(j < H*W){
            p = num2xy[j]; int x = p.first; int y = p.second;
            int cost = abs(x-pre_x) + abs(y-pre_y);
            dist[i].push_back(dist[i].back() + cost);
            pre_x = x; pre_y = y;
            j += D;
        }
    }

    int Q; cin >> Q;
    REP(i,Q){
        int l,r;
        cin >> l >> r; l--; r--;
        cout << dist[r%D][r/D] - dist[l%D][l/D] << endl;
    }

    return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

int countIndentLevel(const string& s) {
    rep(j, s.size()) {
        if (s[j] != '.') {
            return j;
        }
    }
}

int updateCnt(V& cnt, const string& s) {
    for (const auto c : s) {
        switch(c) {
            case '(': cnt[0]++; break;
            case ')': cnt[0]--; break;
            case '{': cnt[1]++; break;
            case '}': cnt[1]--; break;
            case '[': cnt[2]++; break;
            case ']': cnt[2]--; break;
        }
    }
}

bool checkValid(const map<V, int>& rule, int R, int C, int S) {
    for (const auto& p : rule) {
        V cnt;
        int indent;
        tie(cnt, indent) = p;
        if (R * cnt[0] + C * cnt[1] + S * cnt[2] != indent) {
            return false;
        }
    }
    return true;
}

void updateAns(V& ans, const VV& brackets, int R, int C, int S) {
    int Q = brackets.size();
    V temp(Q);
    rep(i, Q) {
        temp[i] = R * brackets[i][0] + C * brackets[i][1] + S * brackets[i][2];
    }

    if (ans.empty()) ans = temp;
    rep(i, Q) {
        if (ans[i] != temp[i]) ans[i] = -1;
    }
}

void solve(const int P, const int Q) {
    map<V, int> rule;
    V cnt(3);
    rep(i, P) {
        string s;
        cin >> s;
        rule[cnt] = countIndentLevel(s);
        updateCnt(cnt, s);
    }

    cnt.assign(3, 0);
    VV brackets(Q, V(3));
    rep(i, Q) {
        brackets[i] = cnt;
        string s;
        cin >> s;
        updateCnt(cnt, s);
    }

    // bool valid[21][21][21];
    V ans;
    rep2(R, 1, 21) {
        rep2(C, 1, 21) {
            rep2(S, 1, 21) {
                // valid[R][C][S] = checkValid(rule, R, C, S);
                if (!checkValid(rule, R, C, S)) continue;
                updateAns(ans, brackets, R, C, S);
            }
        }
    }

    rep(i, ans.size()) {
        cout << (i != 0 ? " " : "") << ans[i];
    }
    cout << endl;
}

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

    int P, Q;
    while (cin >> P >> Q, P) {
        solve(P, Q);
    }
}

Measured memory_bytes: 3080
package main

import (
        "fmt"
)

func main() {
        var n, q int
        fmt.Scan(&n, &q)
        var s string
        fmt.Scan(&s)
        culumtive := make([]int, n)
        num := 0
        for i := 1; i < n; i++ {
                if s[i] == 'C' && s[i-1] == 'A' {
                        num++
                }
                culumtive[i] = num
        }
        var l, r int
        for i := 0; i < q; i++ {
                fmt.Scan(&l, &r)
                a := culumtive[r-1] - culumtive[l-1]
                fmt.Printf("%d\n", a)
        }
}

Measured memory_bytes: 8108
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

      String[] lns = in.readLine().split(" ");
      int n = Integer.parseInt(lns[0]);
      int m = Integer.parseInt(lns[1]);
      City[] city = new City[m];
      City[] city2 = new City[m];
      int[] p = new int[n+1];

      int x,y;
      for(int i=0; i<m; i++) {
        lns = in.readLine().split(" ");
        x = Integer.parseInt(lns[0]);
        y = Integer.parseInt(lns[1]);
        city[i] = new City(i, x, y);
        city2[i] = city[i];
      }

      Arrays.parallelSort(city2, new Comparator<City>() {
        public int compare(City a, City b) {
          if(a.y == b.y) return 0;
          return a.y > b.y ? 1 : -1;
        }
      });

      for(int i=0; i<m; i++) {
        city2[i].no = ++p[city2[i].p];
      }

      // String no;
      StringBuilder buf1 = new StringBuilder();
      StringBuilder buf2 = new StringBuilder();
      for(int i=0; i<m; i++) {
        // no = String.format("%06d%06d", city[i].p,city[i].no);
        buf1.append(city[i].p);
        for(int j=buf1.length(); j<6; j++)
          buf2.append("0");
        buf2.append(buf1);
        buf1.setLength(0);
        buf1.append(city[i].no);
        for(int j=buf1.length(); j<6; j++)
          buf2.append("0");
        buf2.append(buf1).append('\n');
        buf1.setLength(0);
        // out.println(no);
      }
      // out.flush();
      System.out.print(buf2);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
  class City {
    int s;
    int p;
    int y;
    int no;

    public City(int s, int p, int y) {
      this.s = s;
      this.p = p;
      this.y = y;
    }
  }
}

Measured memory_bytes: 54532
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
signed main(){
	string st;
	cin>>st;
	int n = st.size();
	vector<int> a(3);
	for(int i=0;i<n;i++){
		a[ st[i] - 'a' ] ++;
	}
	sort( a.begin(), a.end() );
	if( a[2] - a[0] <= 1 ){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>
#include<string>
typedef unsigned long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define F first
#define S second
using namespace std;
const ll INF = 1e12;

int main() {
  int a,b;
  cin>>a>>b;
  if(a>12)cout<<b<<endl;
  else if(a<6)cout<<0<<endl;
  else cout<<b/2<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(a <= 8 && b <= 8)
			System.out.println("Yay!");
		else
			System.out.println(":(");

	}

}


Measured memory_bytes: 22996
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    ll N, A, B;
    cin >> N >> A >> B;
    ll c = A + B;
    ll d = N / c;
    ll e = N % c;
    ll res = d * A + min(e, A);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    B = list(map(int, readline().split()))

    A = []
    while B:
        for i in range(len(B)-1, -1, -1):
            if B[i] == i+1:
                A.append(B[i])
                del B[i]
                break

        else:
            print(-1)
            sys.exit()

    A = A[::-1]
    for a in A:
        print(a)


main()


Measured memory_bytes: 3060
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define rev reverse
#define all(x) x.begin(), x.end()
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define endl '\n'
#define ull unsigned long long
#define sz(x) (int)x.size()

template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll inf = 1e9+7;
const ll N = 1e5+1;
const ll mod = 1e9+7;
const ll P = 31;

int main() {
    IOS
    ll a, b;
    cin >> a >> b;
    if(b >= a) {
        cout << "unsafe" << endl;
    }
    else {
        cout << "safe" << endl;
    }
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
using namespace std;
int main() {
  long long n;
  cin >> n;
  if (n % 2ll == 1ll) {
    cout << 0 << endl;
  } else {
    long long ans = 0, x = 10ll;
    while (x <= n) {
      ans += n / x;
      x *= 5;
    }
    cout << ans << endl;
  }
  return 0;
}

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

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

long long ben(long long n, long long c, long long d){
    long long r = gcd(c, d);
    long long l = c / r * d;

    return n - n/c - n/d + n/l;    
}

int main(){

    long long a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << ben(b, c, d) - ben(a-1, c, d) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int a, b;
    cin >> a >> b;
    cout << (a + b) % 24 << endl;

    return 0;
}

Measured memory_bytes: 256
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;typedef vector<ll> vll;
#define fill(a) memset(a, 0, sizeof (a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const int INF = 1e9 + 10;
const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;

int main(){
        _ios;

        int n,m;
        cin >> n>> m;
        int ans=n*n-n+m*m - m;
        cout<<ans/2;

return 0;
}







Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		ManyFormulas game = new ManyFormulas();
//		game.run();
		game.runWithBit();
	}
}

class ManyFormulas {
	
	String S;
	String[] nums;
	int N;
	
	ManyFormulas() {
		Scanner cin = new Scanner(System.in);
		this.S = cin.nextLine();
		this.nums = new String[S.length()];
		char[] tmp = S.toCharArray();
		for (int i = 0; i < S.length(); i++) {
			nums[i] = String.valueOf(tmp[i]);
		}
		this.N = nums.length;
	}
	
//	void run() {
////		boolean[] contained = new boolean[nums.length];
////		long allSum = dfs(0, contained);
//		System.out.println(allSum);
//	}
	
	void runWithBit() {
		long allSum = 0;
		for (int i = 0; i < 1 << N - 1; i++) {
			allSum += calculateSumWith(i);
		}
		System.out.println(allSum);
	}
	
	long calculateSumWith(int bit) {
		long sum = 0;
		long tmpNum = 0;
		int digit = 1;
		bit = bit << 1;
		
		for (int j = 0; j < N; j++) {
			if ((bit >> j & 1) == 1) {
				sum += tmpNum;
				tmpNum = 0;
				digit = 1;
			}
			tmpNum += Long.valueOf(nums[N - j - 1]) * digit;
			digit *= 10;
		}
		sum += tmpNum;
		return sum;
	}
	
//	long dfs(int depth, boolean[] contained) {
//		if (depth == nums.length - 1) {
//			return calculateSum(contained);
//		}
//		return dfs(depth + 1, copyArray(contained)) + dfs(depth + 1, setFlagAtIndex(contained, depth)); 
//	}
//	
//	long calculateSum(boolean[] contained) {
//		long sum = 0;
//		long tmpNum = 0;
//		int digit = 1;
//	
//		for (int i = contained.length - 1; i >= 0; i--) {
//			if (contained[i]) {
//				sum += tmpNum;
//				digit = 1;
//				tmpNum = 0;
//			} 
//			tmpNum += Long.valueOf(nums[i]) * digit;
//			digit *= 10;
//		}
//		sum += tmpNum;
//		return sum;
//	}
//	
//	boolean[] setFlagAtIndex(boolean[] arr, int index) {
//		boolean[] newArr = copyArray(arr);
//		newArr[index] = true;
//		return newArr;
//	}
//	
//	boolean[] copyArray(boolean[] arr) {
//		boolean[] newArr = new boolean[arr.length];
//		for (int i = 0; i < arr.length; i++) {
//			newArr[i] = arr[i];
//		}
//		return newArr;
//	}
//	
//	void printArray(boolean[] arr) {
//		for (int i = 0; i < arr.length; i++) {
//			System.out.print(arr[i] + " ");
//		}
//		System.out.println();
//	}
}


Measured memory_bytes: 9812
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C;
  cin >> A>>B>>C;
 
  if (A<B) {
     if (C<B){
       if (A<C){
       cout << "Yes" << endl;
       }
       else{
       cout << "No" << endl;
       }
     }
    else{
    cout << "No" << endl;
    }
 }
  
 else {
     if (C>B){
       if (A>C){
       cout << "Yes" << endl;
       }
       else{
       cout << "No" << endl;
       }
     }
    else{
    cout << "No" << endl;
    }
 }
}

Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <bits/stdc++.h>
#include <string>
using namespace std;
int keta(long N){
    for(int i=1;;i++){
        N /= 10;
        if(N==0)return i;
    }
}

int main(){
    long N;
    cin>>N;
    long num = (long)floor(sqrt(N));
    for(;;num--){
        if(N%num==0){     
            cout<<max(keta(num),keta(N/num))<<endl;
            return 0;
        }
    }

}

Measured memory_bytes: 256