akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
using namespace std;
typedef long long               ll ;
typedef long double             ld ;
typedef unsigned long long      ull ;
typedef pair<int,int>           pii ;
typedef vector<int>             vi ;
typedef vector<vector<int>>     vvi ;
#define fast() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mem(a) memset(a,0,sizeof(a))
#define mod  1000000007LL
#define     ff          first
#define     ss          second
#define print(p) for(auto x:p){cout<<x<<" ";}


#define bug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl ;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ' ' ;
    err(++it, args...);
}








ll a[100005],b[100005],n,cnt;

int main(){
    fast()
    cin>>n;
    for(ll i=0;i<=n;i++){
        cin>>b[i];//mons
    }
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }

    for(ll i=0;i<=n;i++){
            //if(b[i]<0)b[i]=0;

            int   p=b[i+1]+b[i];
            if(a[i]>=p||a[i]>=b[i]){
                     // cout<<"1"<<endl;
                    if(a[i]>=p){

                        cnt+=p;
                        b[i]=0;
                        b[i+1]=0;
                    }
                    else{
                        if(a[i]==b[i]){
                            cnt+=a[i];//ERROR
                        //b[i+1]+=a[i]-b[i];
                        }
                        else if(a[i]>b[i]){
                            cnt+=b[i];
                            if(b[i+1]>=a[i]-b[i])cnt+=a[i]-b[i];
                            b[i+1]-=a[i]-b[i];

                        }
                    }

            }
            else if(p>=a[i]||b[i]>=a[i]){
                     // cout<<"2"<<endl;
                if(b[i]>=a[i]){
                    cnt+=a[i];
                    //b[i+1]=0;
                }
                else{
                    cnt+=a[i];
                    b[i+1]=(b[i]-a[i]);
                }
            }

           // bug(cnt,b[i],p)

    }
    cout<<cnt<<endl;


     return 0;
}



Measured memory_bytes: 1792
n = gets.to_i
ls = gets.split.map &:to_i

ls.sort!

count = 0

(0...ls.size).to_a.combination(3).each{ |x|
	if
		ls[x[0]] != ls[x[1]] &&
		ls[x[1]] != ls[x[2]] &&
		ls[x[0]] + ls[x[1]] > ls[x[2]]
	then
		count += 1
	end
}

puts count


Measured memory_bytes: 14384
n, m = map(int, input().split())
p = [0, 1]
mod = 10 ** 9 + 7
for i in range(2,max(n, m) + 1):
    p.append(p[i-1] * i % mod)
if n == m:
    print(2*p[n]*p[m] % mod)
elif abs(n-m) == 1:
    print(p[n]*p[m] % mod)
else:
    print(0) 


Measured memory_bytes: 7060
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N;
	in >> N;
	std::vector<LL>H(N);
	rep(i, N) in >> H[i];

	LL ans = 0;
	rep(i, N)
	{
		bool ok = true;
		rep(j, i)
		{
			if (H[j] > H[i])
			{
				ok = false;
				break;
			}
		}
		if (ok) ++ans;
	}
	out << ans << std::endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define break break
#define continue continue
#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define all(obj) (obj).begin(), (obj).end()
#define lpair pair<ll, ll>
#define vint vector<ll>
#define vinput(name) for(int i=0; i<(int)(name.size()); i++) cin >> name[i];
#define voutput(name) for(int i=0; i<(int)(name.size()); i++) cout << name[i] << endl;
typedef long long ll;

using namespace std;

ll ans = 0;

int main(void){
	ll n; cin >> n;
	vector<lpair> xl(n);
	rep(i, n) cin >> xl[i].first >> xl[i].second;
	sort(all(xl));
	
	ans = n;
	rep(i, n-1){
		if(xl[i+1].first-xl[i+1].second < xl[i].first+xl[i].second){
			ans--;
			if(xl[i].first+xl[i].second <= xl[i+1].first+xl[i+1].second){
				xl[i+1] = xl[i];
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
   int main()
   {
   int a,b,c;
	while(scanf("%d%d",&a,&b)!=EOF)
	   {
	   b=2*b+1;
		if(a%b==0)
		c=a/b;
		else
		c=a/b+1;	
	printf("%d\n",c);	
		}	
	}

Measured memory_bytes: 256
#include <stdio.h>

int main(){


	int m, f, r, sum;
	

	while(1){
	
		scanf( "%d %d %d", &m, &f, &r );

		if( m==-1 && f==-1 && r==-1 )
			break;

		sum = m + f;

		if( m == -1 || f == -1 ) printf( "F\n" ); 
		else if(sum >= 80) printf( "A\n" );
		else if(65 <= sum && sum < 80 ) printf( "B\n" );
		else if(50 <= sum && sum < 65 ) printf( "C\n" );
		else if(30 <= sum && sum < 50 ){
			if( 50 <= r )	printf( "C\n" );
			else printf( "D\n" );
		}
		else if( 30 > sum ) printf( "F\n" );
	}


	return 0;


}

Measured memory_bytes: 584
import sys
from bisect import bisect_right as bi_r

inf = float('inf')

n, *A = map(int, sys.stdin.read().split())

def main():
    res = [inf] * n
    for a in A[::-1]:
        i = bi_r(res, a)
        res[i] = a

    for i in range(n):
        if res[i] == inf:
            return i
    return n
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 14092
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int temp,sum=0,s;
	double m;
	for(int i=0;i<4;i++){
		scanf("%d",&temp);
		sum+=temp;
	}
	m = sum/60;
	s = sum%60;
	printf("%d\n%d\n",(int)m,s);
}

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

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<int>> a(H+1, vector<int>(W+1)), ans;
    for(int i = 1;i <= H;i++){
        for(int j = 1;j <= W;j++){
            cin >> a[i][j];
        }
    }
    for(int i = 1;i <= H;i++){
        for(int j = 1;j < W;j++){
            if(a[i][j]&1){
                ans.push_back({i, j, i, j+1});
                a[i][j]--;
                a[i][j+1]++;
            }
        }
    }
    for(int i = 1;i < H;i++){
        if(a[i][W]&1){
            ans.push_back({i, W, i+1, W});
            a[i][W]--;
            a[i+1][W]++;
        }
    }
    cout << ans.size() << endl;
    for(auto a : ans){
        cout << a[0] << " " << a[1] << " " << a[2] << " " << a[3] << endl;
    }
}

Measured memory_bytes: 9904
#include<stdio.h>
int main(){
int a,b;
scanf("%d%d",&a,&b);
if(a>=13){
    printf("%d\n",b);
}
else if(a>5 && 13>a){
        printf("%d\n",b/2);
}
else{
        printf("0\n");
}
return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define each(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define all(c) c.begin(),c.end()
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;
const int inf=(int)1e9;
const double EPS=1e-9, INF=1e12;

string s[100];

int main(){
	int n;
	cin >> n;
	vector<vector<pi> > e(n);
	cin.ignore();
	map<string, int> l;
	rep(i, n){
		getline(cin, s[i]);
		s[i].erase(s[i].end() - 1);
		if(s[i].substr(0, 4) != "goto") l[s[i]] = i;
	}
	rep(i, n){
		if(s[i].substr(0, 4) == "goto"){
			e[i].pb(mp(l[s[i].substr(5)], 0));
			e[i].pb(mp(i + 1, 1));
		}
		else e[i].pb(mp(i + 1, 0));
	}
	priority_queue<pi> q;
	set<int> v;
	q.push(mp(0, 0));
	while(!q.empty()){
		int c = q.top().second, co = q.top().first;
		q.pop();
		if(v.count(c)) continue;
		v.insert(c);
		if(c == n){
			cout << -co << endl;
			return 0;
		}
		rep(i, e[c].size()) q.push(mp(co - e[c][i].second, e[c][i].first));
	}
	return 0;
}

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

int main(){
	long long n,a,b;
    cin>>n>>a>>b;
	if(n == 1){
		if(a!=b)cout<<0<<endl;
		else cout<<1<<endl;
		return 0;
	}
	if(a>b){
		cout<<0<<endl;
		return 0;
	}
	cout<<(b*(n-1)+a)-((a*(n-1))+b)+1<<endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
const double PI = 3.14159265358979323846264338327950;
inline int newline() { putchar('\n'); return 0; }

int main() {
    int n;
    cin(n);

    vector<pair<int, int>> points(n);
    rep2(i, n) {
        int x, y;
        cin(x); cin(y);
        points[i] = make_pair(x, y);
    }

    double sum = 0;
    rep2(i, n) {
        rep2(j, n) {
            if (i == j) continue;

            int dx = points[i].first - points[j].first;
            int dy = points[i].second - points[j].second;

            double d = pow(dx * dx + dy * dy, 0.5);
            sum += d / n;
        }
    }

    printf("%0.12f", sum);
    return 0;
}

Measured memory_bytes: 4200
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x; 
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x; 
        return true;
    }
    return false;
}
template<typename Val>
bool bitcheck(Val bit, size_t idx) {
    return bit & (1 << idx);
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

void solve() {
    ll n, a, b; cin >> n >> a >> b;
    ll count = 0;
    if (a != 0) {
        count = (n / (a+b)) * a + min(a, n % (a + b));   
    }
    cout << count << endl;
}

signed main() {
    solve();
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll; const ll MM = 1000000000;ll mod = MM + 7;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;

int main() {
    int h, a; cin >> h >> a;
    if(h % a == 0) cout << h / a << endl;
    else cout << h / a + 1 << endl;
}

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

    #define ll long long
    #define ff first
    #define ss second
    #define pb push_back
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define MOD 1000000007
    #define pll pair<ll,ll>
constexpr ll INF = 1999999999999999997; 
    #define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
    int main() {
      fastio;

      ll x;
      cin>>x;
      //map<pll>m;
      /// a[]={500,100,50,10,5,1};
      ll a,b;
      a=x/500;
      x=x%500;
      b=x/5;
      ll ans=0;
      ans=ans+(a*1000)+(b*5);
      
      cout<<ans<<endl;

    }

Measured memory_bytes: 256
#include<stdio.h>
 
void swap(int* a,int* b){
  int tmp=*a;
  *a=*b;
  *b=tmp;
}
 
int Partition(int A[],int p,int r){
  int x = A[r];
  int i=p-1,j;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      swap(&A[i],&A[j]);
    }
  }
  swap(&A[i+1],&A[r]);
  return i+1;
}
 
int main(){
  int n,i,x;
  int A[100000];
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  x=Partition(A,0,n-1);
  for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i==x)printf("[");
    printf("%d",A[i]);
    if(i==x)printf("]");
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2088
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const ll MOD = 998244353;
const ll INF = 2e15 + 10;
const ll MAX = 1e14 + 10;
const ld EPS = 1e-9;
const int N = 1e5 + 10;
const int M = 1e5 + 10;

vector<int> g[N];
bool used[N];
vector<int> vec;

void dfs(int v) {
    used[v] = true;
    for (auto u: g[v])
        if (!used[u])
            dfs(u);
    vec.pb(v);
}

void solve() {
    int n, m;
    cin >> n >> m;
    fr(i, m) {
        int v, u;
        cin >> v >> u;
        g[--v].pb(--u);
    }
    fr(i, n)
        if (!used[i])
            dfs(i);
    reverse(vec.begin(), vec.end());
    //for (auto x: vec) cout << x << " ";cout << endl;
    vector<int> pos(n);
    fr(i, n)
        pos[vec[i]] = i;

    vector<int> d(n, 1);
    fr(i, n)
        for (auto u: g[vec[i]])
            d[pos[u]] = max(d[pos[u]], d[i] + 1);
    cout << *max_element(d.begin(), d.end()) - 1;

}



int main() {
    //freopen("a.in", "r", stdin);
    ios_base::sync_with_stdio(false);
    solve();
}


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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
	int n, a, b;
	cin >> n >> a >> b;
	int d[3] = { };
	REP(i, n){
		int x;
		cin >> x;
		if(x <= a) d[0]++;
		else if(x<=b) d[1]++;
		else d[2]++;
	}
	cout << min({d[0], d[1], d[2]}) << endl;
	return 0;
} 

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    for(int i=0; i<n; i++){
        cin >> a.at(i);
    }
    b=a;
    sort(a.begin(),a.end());
    for(int i=0; i<n; i++){
        if(a.at(n-1)-b.at(i)) cout << a.at(n-1) << endl;
        else cout << a.at(n-2) << endl;
//        cout << b.at(i) << endl;
    }
}

Measured memory_bytes: 4764
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#define MAX 10000
#define INF 1 << 30

int n, d[MAX];
vector<pair<int, int> > V[MAX];
bool vis[MAX];

void dijkstra(int s){
  for ( int i = 0; i < n; i++)d[i] = INF;
  for ( int i = 0; i < n; i++){ vis[i] = false; }
  d[s] = 0;
  priority_queue<pair<int, int> > PQ;
  PQ.push(make_pair(0, s));
  while ( !PQ.empty() ){
    s = PQ.top().second; PQ.pop();
    if ( vis[s] ) continue;
    vis[s] = true;
    for ( int i = 0; i < V[s].size(); i++){
      pair<int, int> f = V[s][i];
      int v = f.first;
      int c = f.second;
      if (!vis[v] && d[v] > d[s] + c ){
        d[v] = d[s] + c;
        PQ.push(make_pair((-1) * d[v], v));
      }
    }
  }
}

int main(){
  cin >> n;

  int u, k, v, c;
  for ( int i = 0; i < n; i++ ){
    cin >> u >> k;
    for ( int j = 0; j < k; j++){
      cin >> v >> c;
      V[u].push_back(make_pair(v, c));
    }
  }

  dijkstra(0);

  for ( int i = 0; i < n; i++){
    cout << i << " " << d[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 7976
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  int M, K; cin >> M >> K;
  if (M==1&&K==0) { cout << "0 0 1 1" << endl; return 0;}
  if (M==1&&K==1) { cout << -1 << endl; return 0;}
  if (pow(2,M)<=K) { cout << -1 << endl; return 0;}
  rep(i,pow(2,M)) if (i!=K) cout << i << " ";
  cout << K << " ";
  for (int i=pow(2,M)-1; i>=0; i--) if (i!=K) cout << i << " ";
  cout << K << endl;
  return 0;
}

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

typedef long long ll;
typedef pair<int,int> ii;

bool ok(int x) {
	set<int> st;
	while(x)
		st.insert(x%10), x/=10;
	return st.size()==3;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int lst[]={3,5,7};
	queue<ll> q; q.push(0);
	int n,ret=0; cin>>n;
	for (int i=0; i<11; i++) {
		int sz=q.size();
		for (int j=0; j<sz; j++) {
			ll cur=q.front(); q.pop();
			if(cur&&cur<=n&&ok(cur))
				ret++;
			for (int k=0; k<3; k++)
				q.push(cur*10+lst[k]);
		}
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
 
using namespace std;
#define taskname "A"
#define pb	push_back
#define mp  make_pair
 
typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int s[maxn * 4],lz[maxn * 4];
int n, m;
 
void build(int x , int l , int r){
    s[x] = -(m - r + 1);
    if(l == r)return;
    int mid = l + r >> 1;
    build(x*2,l,mid);build(x*2+1,mid+1,r);
}
void push(int x , bool key){
    s[x]+=lz[x];
    if(key)lz[x*2]+=lz[x],lz[x*2+1]+=lz[x];
    lz[x]=0;
}
void update(int x , int l,int r , int L , int R){
    push(x,l!=r);
    if(l > R || L > r)return;
    if(L <= l && r <= R){
        lz[x]++;push(x,l!=r);
        return;
    }
    int mid = l + r >> 1;
    update(x*2,l,mid,L,R);update(x*2+1,mid+1,r,L,R);
    s[x]=max(s[x*2],s[x*2+1]);
}
vector<int> q[maxn];
int query(int x , int l,int r , int L , int R){
    push(x,l!=r);
    if(l > R || L > r)return -1e9;
    if(L <= l && r <= R){
        return s[x];
    }
    int mid = l + r >> 1;
    return max(query(x*2,l,mid,L,R),query(x*2+1,mid+1,r,L,R));
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	if(fopen(taskname".INP","r")){
        freopen(taskname".INP", "r",stdin) ,
        freopen(taskname".OUT", "w",stdout);
	}
    cin >> n >> m;
    for(int i = 1 ; i <= n ; ++i){
        int l , r;cin >> l >> r;
        q[l].pb(r);
    }
    build(1,1,m+1);
    int res = max(0,n-m);
    for(int i = 0 ; i <= m ; ++i){
        for(auto r : q[i]){
            update(1,1,m+1,1,r);
//            cout << 1 << " " << r << endl;
        }
//        cout << -i + s[1] << endl;
        res = max(res,-i+s[1]);
    }
    cout << res;
}

Measured memory_bytes: 14080
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);
const int H = 50010;
ll dp[1010][H];
PII arr[1010];
int main(){
    ll apk = LLONG_MAX;
    apk/=10000;
    loop(i,0,1010){
        loop(j,0,H){
            if(j == 0)dp[i][j] = 0;
            else dp[i][j] = apk;
        }
    }
    int h,n;
    cin >> h >> n;
    loop(i,1,n+1)cin >> arr[i].F >> arr[i].S;
    loop(i,1,n+1){
        loop(j,1,H){
            dp[i][j] = dp[i-1][j];
            if(j >= arr[i].F)dp[i][j] = min({dp[i][j],dp[i][j-arr[i].F]+arr[i].S,dp[i-1][j-arr[i].F]+arr[i].S});
        }
    }
    ll ans = LLONG_MAX;
    loop(i,h,H){
        ans = min(dp[n][i],ans);
    }
    cout << ans;
   return 0;
}

Measured memory_bytes: 395008
n,m = gets.split.map(&:to_i)
a = []
m.times { a << gets.to_i }
# dp[i] <= i段目までの移動方法の総数
dp = [1,1]
broken = a.shift # 壊れている床を左から順に取り出す。
if broken == 1
  broken = a.empty? ? nil : a.shift
  dp[1] = 0 # 壊れている場合は0とする
end
(2..n).each do |i|
  if broken == i
    dp[i] = 0
    broken = a.empty? ? nil : a.shift
    next
  end
  dp[i] = dp[i-1] + dp[i-2]
end
p dp[n] % 1000000007


Measured memory_bytes: 445076
/**
 * @author      : Luis Miguel Baez <es.luismiguelbaez@gmail.com>
 * @created     : Wednesday August 19, 2020
 */

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ms(arr, value) memset(arr, value, sizeof(arr))
#define finally(value) {cout << value << '\n'; return;}
#define ll    int64_t

const int oo = int(1e9);
const ll lloo  = (ll)(1e18);
const int N_MAX = int(3001);

class Task {
public:
    int N;
    vector<int> A;

    ll dp[N_MAX][N_MAX];

    ll go(int l, int r, bool player) {
        if(l > r || l > N || r < 0) return 0LL;
        ll &ans = dp[l][r];
        if(ans != -1LL) return ans;
        ll sign = player?1LL:-1LL;
        ll first = A[l]*sign + go(l+1, r, !player);
        ll second = A[r]*sign + go(l, r-1, !player);
        ans = 0;
        if(player) ans = max(first, second);
        else ans = min(first, second);
        return ans;
    }

    void solveOne(istream &in, ostream &out) {
        in >> N;
        A.resize(N+1);
        for(int i = 1; i <= N; ++i){
            in >> A[i];
        }
        ms(dp, -1LL);
        ll ans = go(1, N, true);
        finally(ans);
    }
    
    void solve(istream &in, ostream &out) {
        int t=1;
        while(t--) solveOne(in, out);
    }
};

auto main() -> int {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    Task solver;
    istream &in(cin);
    ostream &out(cout);
    solver.solve(in, out);
    return 0;
}


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

signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin>>a[i];

  int sum=0;
  for(int i=0;i<n;i++) sum+=a[i];
  
  const int MOD = 998244353;

  vector<int> dp(sum+1,0);
  dp[0]=1;

  for(int i=0;i<n;i++){
    vector<int> nx(sum+1,0);
    for(int j=0;j<=sum;j++){
      nx[j]+=dp[j]*2%MOD;
      if(j+a[i]<=sum) nx[j+a[i]]+=dp[j];
    }
    for(int j=0;j<=sum;j++)
      dp[j]=nx[j]%MOD;
  }

  vector<int> dp2(sum+1,0);
  dp2[0]=1;

  for(int i=0;i<n;i++){
    vector<int> nx(sum+1,0);
    for(int j=0;j<=sum;j++){
      nx[j]+=dp2[j];
      if(j+a[i]<=sum) nx[j+a[i]]+=dp2[j];
    }
    for(int j=0;j<=sum;j++)
      dp2[j]=nx[j]%MOD;
  }

  int ans=0;
  if(sum%2==0){
    ans-=dp2[sum/2]*3%MOD;
    ans+=MOD;
  }
  
  for(int j=(sum+1)/2;j<=sum;j++){
    ans+=dp[j]*3;
    ans%=MOD;
  }
  ans=MOD-ans;

  int po3=1;
  for(int i=0;i<n;i++) po3=po3*3%MOD;
  ans+=po3;
  ans%=MOD;
  
  cout<<ans<<endl;
}


Measured memory_bytes: 2376
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
  int N;
  cin >> N;
  
  vector<int> W(N);
  cin >> W.at(0);
  for(int i = 1;i < N;i++){
    int w;
    cin >> w;
    
    W.at(i) = W.at(i-1) + w;
  }
  
  int ans = 100000;
  for(int i = 1;i < N;i++){
    int S1 = W.at(i-1), S2 = W.at(N-1) - S1;
    ans = min(ans, abs(S1 - S2));
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int,int> pair2;
typedef std::pair<int,pair2> pair3;
const ll INF = 1LL<<60;

int main(){
  ll N;
  cin>>N;
  ll C[N-1],S[N-1],F[N-1];
  for(ll i=0;i<N-1;i++){
    cin>>C[i]>>S[i]>>F[i];
  }
    ll ans=0;  
  for(ll i=0;i<N-1;i++){
	ans=0;
    for(ll j=i;j<N-1;j++){
      if(ans<=S[j]){ans=S[j];}
      else {ll start=(ll)(ans/(double)(F[j])+0.99999999);
           ans=start*F[j];
            //cout<<"start"<<start;
           }
      //cout<<"j"<<j<<"ans"<<ans<<" "<<C[j]<<endl;
      ans=ans+C[j];
      //cout<<ans<<endl;
    }
    cout<<ans<<endl;
    
  }
  cout<<0<<endl;
  
}


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

int main(){
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    if (N <= K)
    {
        cout << N * X << endl;
    }
    else{
        cout << (K * X) + (N - K) * Y << endl;
    }
    
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
char back(char a,int i)
{
  for(;i--;)
    {
      if(a=='z')
	a='a';
      else
	a++;
    }
  return a;
}

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      string s;
      cin >>s;
      vector<pair<int,int> > v;
      for(;n--;)
	{
	  int a,b;
	  cin>>a>>b;
	  v.push_back(pair<int,int>(a,b) );
	}
      for(int i=v.size()-1;i>=0;i--)
	{
	  int a=v[i].first;
	  int b=v[i].second;
	  swap(s[a-1],s[b-1]);
	  s[a-1]=back(s[a-1],abs(a-b));
	  s[b-1]=back(s[b-1],abs(a-b));	  
	}
      cout<<s<<endl;
    }
}

Measured memory_bytes: 1208
import * as fs from 'fs';

namespace AtCoder.abc160 {

    export class ProgramB {
        args: string[];

        constructor(args: string[]) {
            this.args = args;
        }

        /**
         * in
         *1024
         * out
         * 2020
         */
        main(): void {
            let x: number = parseInt(this.args[0], 10);

            let ans :number=0;
            while(x>4) {
                if (x>=500) {
                    ans+=1000;
                    x-=500;
                } else if (x>=5) {
                    ans+=5;
                    x-=5;
                }
            }
            console.log(ans);
        }
    }

}

const args = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
const prg = new AtCoder.abc160.ProgramB(args);
prg.main();




Measured memory_bytes: 7500
n = input()
memo = [[0] * n for _ in range(26)]
for i in range(n):
  for c in raw_input():
    memo[ord(c) - ord('a')][i] += 1
res = ''
for i, count_per_char in enumerate(memo):
  res += chr(ord('a') + i) * min(count_per_char)
print res

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.txt", "r", stdin);
		//freopen("out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0), cin.tie(0);

	ll n, k;
	cin >> n >> k;
	if ((n+1)/2 >= k)
		cout << "YES\n";
	else
		cout << "NO\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
using namespace std;

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

    int end = s[0] == s[s.length() - 1] ? 2 : 3;
    int rem = s.length() - end;

    cout << (rem % 2 == 0 ? "First" : "Second") << endl;

    return 0;
}


Measured memory_bytes: 512
N, M = gets.split.map(&:to_i)
l = Array.new(N){Array.new}
M.times{|m|
    a, b = gets.split.map{|i|i.to_i - 1}
    l[a] << b
    l[b] << a
}
#warn l.inspect

r = Array.new(N)
r[0] = 0
q = [0]
loop{
    c = []
    q.each{|n|
        l[n].each{|m|
            next if r[m]
            r[m] = n
            c << m
        }
    }
    #warn c.inspect
    break if c.empty?
    q = c
}

puts "Yes"
puts r[1, N - 1].map{|i|i + 1}


Measured memory_bytes: 33756
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
ll int large=(ll int)1e13+7;
ll int mod=(ll int)1e9+7;
ll int const N=(ll int)1e5+10;

ll int mod_exp(ll int x,ll int n)
{
    ll int result=1;
    while(n>0)
    {
        if(n%2==1)
            result=(result*x)%mod;
        x=(x*x)%mod;
        n=n/2;
    }
    return result;
}

ll int mod_inverse(ll int a)
{
    return mod_exp(a,mod-2);
}


ll int finde(ll int a,ll int par[])
{
    if(par[a]<0)
        return a;
    ll int res=finde(par[a],par);
    par[a]=res;
    return res;
}

void unione(ll int a,ll int b,ll int par[])
{
    if((a=finde(a,par))==(b=finde(b,par)))
    return;
    else
    {
       par[a]+=par[b];
       par[b]=a;
    }
}


int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
ll int T,i,j,ij;
T=1;
//cin>>T;
while(T--)
{
  ll int n;
  cin>>n;
  cout<<n+(n*n)+(n*n*n);

}
return 0;
}
















Measured memory_bytes: 3652
from collections import deque
from copy import deepcopy, copy
N = 3
def g(i, j, a):
    if i > j:
        i, j = j, i
    return a[:i] + a[j] + a[i + 1:j] + a[i] + a[j + 1:]
def MAIN():
    m = {8:{7, 5}, 7:{8, 6, 4}, 6:{7, 3}, 5:{8, 4, 2}, 4:{7, 5, 3, 1}, 3:{6, 4, 0}, 2:{5, 1}, 1:{4, 2, 0}, 0:{3, 1}}
    MAP = "".join(input().replace(" ", "") for _ in range(N))
    start = MAP.find("0")
    goal = "123456780"
    dp = deque([(0, start, MAP)])
    LOG = {MAP}
    while dp:
        cnt, yx, M = dp.popleft()
        if M == goal:
            print(cnt)
            break
        cnt += 1
        for nyx in m[yx]:
            CM = g(yx, nyx, M)
            if not CM in LOG:
                dp.append((cnt, nyx, CM))
                LOG.add(CM)
MAIN()



Measured memory_bytes: 31348
//For fast competitive programming

//INCLUDE
#include <bits/stdc++.h>
using namespace std;

//DATA_TYPES
typedef long long ll; 
typedef vector<int> vi;
typedef pair<int, int> ii; 
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f; //Infinity

//INITIALISING
//memset(arr, 0, sizeof arr);
//vi v(N, 0);

int main()
{
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(NULL);
	
	//write your code here
	int n;
	cin>>n;
    if (((n%10)==2)||((n%10)==4)||((n%10)==5)||((n%10)==7)||((n%10)==9))
	cout<<"hon";
	else if (((n%10)==0)||((n%10)==1)||((n%10)==6)||((n%10)==8))
	{
	    cout<<"pon";
	}
	else
	cout<<"bon";
	return 0;
}

Measured memory_bytes: 3648
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

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

ll a[50];
signed main(void)
{
  ll k;
  cin >> k;

  ll tmp = k / 50;
  REP(i, 50) a[i] = 50 + tmp - 1;

  ll p = k % 50;
  REP(i, p) {
    a[i] += 50;
    REP(j, 50) {
      if(i != j) a[j]--;
    }
  }

  cout << 50 << endl;
  REP(i, 50) {
    cout << a[i];
    if(i != 49) cout << " ";
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#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;

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

    int ans = 0;
    rep(i, 3) {
        if(s[i] == t[i]) {
            ans++;
        }
    }

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

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

using namespace std;

typedef long long ll;
const int Nmax = 1e5 + 5;

string S[Nmax];
int n, i;
ll L, ans = 0;

ll result (ll x)
{
    int i;
    for(i=1; (x & ((1LL<<i) - 1)) == 0 ; ++i);
    return (1LL<<(i-1));
}

class Trie
{
    Trie *left, *right;
    bool used;
    public:
        Trie() { left = right = NULL; used = 0; }

        void add(string &S, int pos)
        {
            if(pos == S.size()) return;

            if(S[pos] == '0')
            {
                if(!left) left = new Trie();
                left -> add(S, pos+1);
            }
            else
            {
                if(!right) right = new Trie();
                right -> add(S, pos+1);
            }
        }

        void solve(string &S, int pos)
        {
            if(pos == S.size()) return;

            if(S[pos] == '0')
            {
                left -> solve(S, pos+1);
                if(!right && !used) ans ^= result(L - pos), used = 1;
            }
            else
            {
                right -> solve(S, pos+1);
                if(!left && !used) ans ^= result(L - pos) , used = 1;
            }
        }

} *root = new Trie();

int main()
{
//    freopen("input", "r", stdin);
    cin.sync_with_stdio(false);

    cin >> n >> L;
    for(i=1; i<=n; ++i)
    {
        cin >> S[i];
        root -> add(S[i], 0);
    }

    ans = 0;
    for(i=1; i<=n; ++i)
        root -> solve(S[i], 0);

    cout << (ans ? "Alice" : "Bob") << '\n';
    return 0;
}


Measured memory_bytes: 7504
#include <cstdio>
#include <iostream>
#include <sstream>

#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <chrono>
#include <random>

using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<i64>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<i64, i64>;

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

int main() { 
  string s;
  cin >> s;
  bool f = true;
  for(int i=0;i<3;i++){
    if(s[i] == s[i+1])f = false;
  }
  cout << (f ? "Good" : "Bad") << endl;
  return 0;
}


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

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

  if(S[0] != 'A')
  {
    cout << "WA" << endl;
    return 0;
  }
  int c=0;
  for(int j=1;j<S.size();j++)
  {
    if(j==1 || j==S.size()-1)
    {
      if(S[j] >='A' && S[j] <='Z')
      {
        cout << "WA" << endl;
        return 0;
      }
    }
    if(2<=j && j<=S.size()-2)
    {
      if(S[j]=='C') c++;
      if(S[j] >='A' && S[j] <='Z' && S[j] != 'C')
      {
        cout << "WA" << endl;
        return 0;
      }
    }
  }
  if(c!=1)
  {
    cout << "WA" << endl;
    return 0;
  }
  cout << "AC" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int	main(void)
{
  	int	a;
  	int	b;
 	int	num;
  	int	i;
  	int	n;
  
  	num = scanf("%d %d", &a, &b);
  	if (num != 2)
      	return (0);
  
  	for(i=0; i<20; i++)
    {
      	n = a * i - (i - 1);
      	if (n >= b)
        {
          	printf("%d", i);
			return (0);
        }
    }
  	return (0);
}

Measured memory_bytes: 128
import Control.Monad
import qualified Data.Vector as V

main :: IO ()
main = do
    n <- readLn
    as <- replicateM n $ do
        a <- readLn
        return a
    print $ solve n $ V.fromList as

solve :: Int -> V.Vector Int -> Int
solve n as = f n 1
    where
        f 0 _ = -1
        f m i | i == 2 = n - m
              | otherwise = f (m-1) $ as V.! (i-1)



Measured memory_bytes: 31612
import java.util.Scanner;


public class Main {
    public static void main(String[] args){
    	Scanner input = new Scanner(System.in);
    	int n = input.nextInt();
    	int m = input.nextInt();
    	int[] num = new int[n];
    	for(int i = 0 ; i < n ; i++){
    		num[i] = (i+1);
    	}
    	for(int i = 0 ; i < m ; i++){
    		String[] s = input.next().split(",");
    		int a = Integer.parseInt(s[0])-1;
    		int b = Integer.parseInt(s[1])-1;
    		int tmp = num[a];
    		num[a] = num[b];
    		num[b] = tmp;
    	}
    	for(int i = 0 ; i < n ; i++){
    		System.out.println(num[i]);
    	}
    }
}

Measured memory_bytes: 17216
#include<stdio.h>
int main(void){
    int A,B,count=0;
    scanf("%d%d",&A,&B);
    count=A*B;
    if(A>=10||A<0)
        count=-1;
    if(B>=10||B<0)
        count=-1;
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


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

	int ans = 0;
	int a, b;
	cin >> a >> b;

	if (a <= b)
	{
		cout << a;
	}
	else
	{
		cout << a - 1;
	}
	cout << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;

#define MAX 100000
#define SENTINEL 2000000000

struct Card {
    char suit;
    int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int left, int mid, int right)
{
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for (i = 0; i < n1; i++) {
        L[i] = A[left + i];
    }
    for (i = 0; i < n2; i++) {
        R[i] = A[mid + i];
    }
    L[n1].value = R[n2].value = SENTINEL;
    i = j = 0;
    for (k = left; k < right; k++) {
        if (L[i].value <= R[j].value) {
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
        }
    }
}

void mergeSort(struct Card A[], int left, int right)
{
    int mid;
    if (left + 1 < right) {
        mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int partition(struct Card A[], int p, int r)
{
    int i, j;
    struct Card x;
    x = A[r];
    i = p - 1;
    for (j = p; j < r; j++) {
        if (A[j].value <= x.value) {
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i + 1], A[r]);
    return i + 1;
}

void quickSort(struct Card A[], int p, int r)
{
    int q;
    if (p < r) {
        q = partition(A, p, r);
        quickSort(A, p, q - 1);
        quickSort(A, q + 1, r);
    }
}

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

    int n, i, v;
    struct Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }

    mergeSort(A, 0, n);
    quickSort(B, 0, n-1);

    for (i = 0; i < n; i++) {
        if (A[i].suit != B[i].suit) {
            stable = 0;
        }
    }

    if (stable) {
        printf("Stable\n");
    } else {
        printf("Not stable\n");
    }

    for (i = 0; i < n; i++) {
        printf("%c %d\n", B[i].suit, B[i].value);
    }

    return 0;
}


Measured memory_bytes: 5520
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//無限大
const ll INF = 1LL << 60;


//------------------------------------------------
int main() {

    //main
    int N, M;
    cin >> N >> M;
    //int A[M];
    int ans = N;
    int Ai;
    rep(i,M){
        cin >> Ai;
        ans -= Ai;
    }

    if( ans < 0 ) ans = -1;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
module segment_tree_mod
    use,intrinsic :: iso_fortran_env
    implicit none

    type seg_tree
        integer(int64):: n,n2
        integer(int64),pointer:: v(:)
    contains
        procedure:: init => st_init
        procedure:: update => st_update
        procedure:: query => st_query
        procedure:: at => st_at
    end type
contains
    function f(a,b) result(ret)
        integer(int64):: a,b,ret
        ret = min(a,b)
    end function

    subroutine st_init(st, n)
        class(seg_tree):: st
        integer(int64),intent(in):: n
        integer(int64):: x
        x=1
        do while(n > x)
            x = 2*x
        end do
        st%n = x
        st%n2 = 2*x-1
        allocate(st%v(st%n2), source=10_int64**16)
    end subroutine

    subroutine st_update(st, i, x)
        class(seg_tree):: st
        integer(int64), intent(in):: i
        integer(int64):: ind
        integer(int64), intent(in):: x
        
        ind = i + st%n - 1
        st%v(ind) = x
        do while(ind > 1)
            ind = ind/2
            st%v(ind) = f(st%v(2*ind), st%v(2*ind+1))
        end do
    end subroutine

    function st_query(st, a, b) result(ret)
        class(seg_tree):: st
        integer(int64), intent(in):: a,b
        integer(int64):: ret
        ret = st_query_sub(st, a, b, 1_8, 1_8, st%n)
    end function

    function st_at(st, i) result(ret)
        class(seg_tree):: st
        integer(int64),intent(in):: i
        integer(int64):: ret
        ret = st%v(i+st%n-1)
    end function

    recursive function st_query_sub(st, a, b, k, l, r) result(ret)
        type(seg_tree),intent(in):: st
        integer(int64),intent(in):: a,b,k,l,r
        integer(int64):: ret, vl, vr

        if (r < a .or. b < l) then
            ret = 10_int64**16
        else if (a <= l .and. r <= b) then
            ret = st%v(k)
        else
            vl = st_query_sub(st,a,b,k*2, l, (l+r)/2)
            vr = st_query_sub(st,a,b,k*2+1, (l+r)/2+1, r)
            ret = f(vl,vr)
        end if
    end function
end module

program main
    use,intrinsic :: iso_fortran_env
    use segment_tree_mod
    implicit none
    integer(int64):: n,nq
    integer(int64):: i,ans,v
    integer(int64), allocatable:: q(:,:)
    type(seg_tree):: x_st, y_st

    read*, n,nq
    allocate(q(2,nq))
    do i=1,nq
        read*, q(:,i)
    end do

    ans = (n-2)*(n-2)
    call x_st%init(n)
    call y_st%init(n)
    do i=1,n-1
        call x_st%update(i,10_int64**16)
        call y_st%update(i,10_int64**16)
    end do
    call x_st%update(n,n)
    call y_st%update(n,n)

    do i=1,nq
        if (q(1,i) == 1) then
            v = x_st%query(q(2,i),n)
            ! print'("v: ",i0)', v
            ans=ans-(v-2)
            call y_st%update(v,min(y_st%at(v),q(2,i)))
        else
            v = y_st%query(q(2,i),n)
            ! print'("v: ",i0)', v
            ans=ans-(v-2)
            call x_st%update(v,min(x_st%at(v),q(2,i)))
        end if
        ! print'(i0)', ans
    end do
    print'(i0)', ans
end program main

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

typedef long long ll;

int main(){
  int n;
  cin >> n;
  ll a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a,a+n);
  ll x=0,y=0;
  int k;
  for(int i=n-1;i>-1;i--){
    if(a[i]==a[i-1]){
      x=a[i];
      k=i-1;
      break;
    }
  }
  for(int i=k-1;i>-1;i--){
    if(a[i]==a[i-1]){
      y=a[i];
      break;
    }
  }
  cout << x*y << endl;
}
  


Measured memory_bytes: 1024
import java.util.Scanner;

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

    while(true) {
      int H = in.nextInt();
      int W = in.nextInt();

      if (H == 0 && W == 0) break;
      
      for (int j = 0; j < W; j++) {
        System.out.print("#");
      }
      System.out.println("");

      for (int i = 1; i < H - 1; i++) {
        System.out.print("#");
        for (int j = 1; j < W - 1; j++) {
          System.out.print(".");
        }
        System.out.println("#");
      }

      for (int j = 0; j < W; j++) {
        System.out.print("#");
      }
      System.out.println("");
      System.out.println();
    }
  }
}

Measured memory_bytes: 33524
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <map>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline bool Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+" ";
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
constexpr const ll INF = 1e15;
constexpr const ll MOD = 1000000007;
constexpr int nx[4] = {1,0,-1,0};
constexpr int ny[4] = {0,1,0,-1};
typedef pair<ll,ll> P;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,x,y;
    cin >> n >> x >> y;
    --x;
    --y;
    vector<vector<P>> ans(n);
    rep(i,n-1){
        rep(j,i+1,n){
            if (i <= x && y <= j){
                ans[x-i+j-y+1].push_back(P(i+1,j+1));
            }
            else if ((x < i && i < y && y <= j)){
                ans[min(abs(x-i)+abs(j-y)+1,abs(y-i)+abs(y-j))].push_back(P(i+1,j+1));
            }
            else if ((i <= x && x < j && j < y)){
                ans[min(abs(x-i)+abs(j-x),abs(x-i)+abs(y-j)+1)].push_back(P(i+1,j+1));
            }
            else{
                ans[min(abs(i-j),abs(i-x)+abs(j-y)+1)].push_back(P(i+1,j+1));
            }
        }
    }
    rep(i,1,n){
        PRINT(ans[i].size());
    }
}


Measured memory_bytes: 45440
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long int ll;
using namespace std;

int main()
{
    string a, b;
    cin >> a >> b;
    int c = 0;
    if(a.size() > b.size()) {
        cout << "GREATER" << endl;
        c = 1;
    }
    else if(a.size()<b.size()) {
        cout << "LESS" << endl;
        c = 1;
    }
    else{
        for(int i=0;i<a.size();i++){
            if(a[i] > b[i]) {
                cout << "GREATER" << endl;
                c = 1;
                break;
            }
            else if(b[i] > a[i]) {
                cout << "LESS" << endl;
                c = 1;
                break;
            }
        }
    }
    if(c == 0) cout << "EQUAL" << endl;
    return 0;

}

Measured memory_bytes: 256