akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
 
import java.util.*;
import java.lang.*;
import java.io.*;

@SuppressWarnings("unchecked")
public class Main implements Runnable {

  static BufferedReader in;
  static PrintWriter out;
 
  public static void main(String[] args) {
      new Thread(null, new Main(), "whatever", 1<<29).start();
  }
 
  public void run() {
    in = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(System.out, false);
 
    try
    {
      // in = new BufferedReader(new FileReader("class_treasurer.txt"));
      // out = new PrintWriter("output.txt");

      int t,x1,n,i,cnt;
      String str;
      String[] token;

      str=in.readLine().trim();
      token=str.split(" ");
      n=Integer.parseInt(token[0]);

      str=in.readLine().trim();

      cnt=1;

      for(i=1;i<n;i++) {
        if(str.charAt(i)!=str.charAt(i-1)) {
          cnt++;
          
        }
      }

      out.println(cnt);

      out.flush();
      out.close();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
}


Measured memory_bytes: 25172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g (n);
    int u, v;
    rep (i, 0, m) {
        cin >> u >> v;
        g[--u].push_back (--v);
    }
    int dist[n][3];
    rep (i, 0, n) rep (j, 0, 3) dist[i][j] = inf;
    queue<pint> q;
    int s, t;
    cin >> s >> t;
    q.push ({--s, 0});
    dist[s][0] = 0;
    while (!q.empty()) {
        int now = q.front().first, cnt = q.front().second;
        q.pop();
        // cout << now << " ";
        for (auto nx : g[now]) {
            if (dist[nx][(cnt + 1) % 3] > dist[now][cnt] + 1) {
                dist[nx][(cnt + 1) % 3] = dist[now][cnt] + 1;
                q.push ({nx, (cnt + 1) % 3});
            }
        }
    }
    /*
    rep (i, 0, n) {
        rep (j, 0, 3) cout << dist[i][j] << " ";
        cout << "\n";
    }
    */
    if (dist[--t][0] == inf) {
        cout << "-1\n";
    } else {
        cout << dist[t][0] / 3 << "\n";
    }
}

Measured memory_bytes: 11188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll a, b, k;
    cin >> a >> b >> k;
    if(a >= k)
    {
        cout << a-k << " " << b << endl;
    }
    else
    {
        ll c = k-a;
        cout << 0 << " " << max(0LL, b-c) << endl;
    }
}


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

int main(){
     int n;
     cin >> n;
     int i = 0;
     while(++i <= n) {
         int x = i;
         if ( x % 3 == 0 ){
             cout << " " << i;
         } else {
             while ( x ) {
                 if ( x % 10 == 3 ) {
                     cout << " " << i;
                     x = 0;
                 } else {
                     x /= 10;
                 }
             }
         }
     }
     cout << endl;
     return 0;
}


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

int main(){
  int a;
  string s,t;
  cin>>a>>s>>t;
  for (int i(0);i<=a;i++){
    string u(s),ui;
    for (int j(a-i);j<a;j++){
      ui+=t[j];
    }
    string x(u+ui);
    bool flag(true);
    for (int j(0);j<a;j++){
      if (x[i+j]!=t[j]) flag=false;
    }
    if (flag==true) {
      cout << a+i << endl;
      return 0;
    }
  }
}


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

#define rep(i,c) for(int i = 0; i < (int)c; ++i)
using llint = long long int ;
using namespace std;

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

    for (auto& e:S) {
        e='x';
    }
    cout<<S<<endl;
}

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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("fibsubseq.in","r",stdin)
#define write()         freopen("fibsubseq.out","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long int
#define endll           printf("\n")
#define pf              printf
#define pi              acos(-1.0)
#define eps             1e-10
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())

bool Check(unsigned int  N,int pos){return (bool)(N & (1LL<<pos));}
ll  Set(unsigned int N,int pos){    return N=N | (1LL<<pos);}
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MX 100005
#define mod  1000000007
#define mod1 1000000009
#define var    int ii,i,j,k,z=0,c=0,t,x,y,l,r,mid
//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};

bool chk(int x,int pos){return (bool)(x&(1<<pos));}
int Set(int x,int pos){return x=x|(1<<pos);}
int clr(int x,int pos){return x=x&~(1<<pos);}

ll n,m,a[16][16],dp[(1<<16)+2],b[(1<<16)+2];
vector<ll> v;

ll fn(ll mask)
{
    if(mask==0)return 0;
    ll &z=dp[mask];
    if(z!=-1)return z;
    ll i;
    z=0;
    for(i=mask;i>0;i=(i-1)&mask)
    {
        if(mask&i==i)
        {
            z=max(z,b[i]+fn(mask&~(i)));
        }
    }
    return z;
}

int main()
{
    ll var;
    mem(dp,-1);
    sfl(n);
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            sfl(a[i][j]);
        }
    }
    m=1<<n;m--;
    for(i=m;i>0;i--)
    {
        v.clear();
        for(j=0;j<n;j++)
        {
            if(i&(1<<j))
            {
                v.pb(j);
            }
        }
        for(j=0;j<v.size();j++)
        {
            for(k=j+1;k<v.size();k++)
            {
                b[i]+=a[v[j]][v[k]];
            }
        }
    }
    z=fn(m);
    cout<<z<<endl;
}


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

string s;

int main(){
    cin>>s;
    int cnt=0;
    int ans=0;
    bool flag=true;
    for(int i=0;i<s.size();i++){
        if(flag){
            if(s[i]=='A'){
                flag=false;
                cnt++;
                ans=cnt;
            }
            continue;
        }else{
            cnt++;
            if(s[i]=='Z')ans=cnt;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {

	string s, t;
	cin >> s >> t;
	int ans = 0;
	rep(i, s.size())if (s[i] != t[i])ans++;
	cout << ans << endl;
	
}

Measured memory_bytes: 3916
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np


def main():
	print((int(input())+1)//2)






	

if __name__ == "__main__":
	main()


Measured memory_bytes: 38256
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
#define MAX 25
#define NIL -1

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

Node T[MAX];

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

int degree(int u)
{
  int cnt = 0;
  if ((T[u].left != NIL))
  {
    cnt++;
  }
  if ((T[u].right != NIL))
  {
    cnt++;
  }
  return cnt;
}

int depth(int u)
{
  if (T[u].parent == NIL)
    return 0;
  return depth(T[u].parent) + 1;
}
int height(int u)
{
  if (u == NIL)
  {
    return -1;
  }
  return max(height(T[u].left), height(T[u].right)) + 1;
}

string type_string(int u)
{
  if (T[u].parent == NIL)
  {
    return "root";
  }
  else if (T[u].left == NIL && T[u].right == NIL)
  {
    return "leaf";
  }
  else
  {
    return "internal node";
  }
}

void print(int u)
{
  int i, c;
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].parent);
  printf("sibling = %d, ", sibling(u));
  printf("degree = %d, ", degree(u));
  printf("depth = %d, ", depth(u));
  printf("height = %d, ", height(u));
  cout << type_string(u) << endl;
}

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

  for (int i = 0; i < n; i++)
  {
    print(i);
  }

  return 0;
}


Measured memory_bytes: 3344
k = int(input())
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += gcd(gcd(a, b), c)
print(ans)

Measured memory_bytes: 76756
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main ()
{
    int n;
    while (cin >> n, n) {
        long long res = 0;
        vector<int> j;

        int t;
        for (int i = 0; i < n; i++) { cin >> t; res += t;}
        for (int i = 0; i < n - 1; i++) { cin >> t; j.push_back(t);}

        sort(j.begin(), j.end(), greater<int>());

        long long tmp = 0;
        tmp = res;
        res *= n;
        for (int i = 1; i < n; i++) {
            tmp = tmp + j[i - 1];
            res = max(res, tmp * (n - i));
        }
        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 1596
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

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

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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


int n,m;
string s;
bool mask[200100];

struct SegmentTree {
private:
    int n;
    vi node;
    vi moto;

public:
    SegmentTree(vi v) {
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, INT_MAX);
        moto.resize(2*n-1, INT_MAX);
        REP(i,sz) {
            node[i+n-1] = v[i];
            moto[i+n-1] = i;
        }
        REPN(i,n-2) {
            node[i] = min(node[2*i+1], node[2*i+2]);
            moto[i] = node[2*i+1] <= node[2*i+2] ? moto[2*i+1] : moto[2*i+2];
        }
    }
    void update(int k, int x){
        k += n-1;
        node[k] = x;
        while(k){
            k = (k-1)/2;
            node[k] = min(node[2*k+1],node[2*k+2]);
            moto[k] = node[2*k+1] <= node[2*k+2] ? moto[2*k+1] : moto[2*k+2];
        }
    }
    pi getmin(int a, int b, int k=0, int l=0, int r=-1){
        if(r<0) r=n;
        if(r<=a || b<=l) return {INT_MAX, INT_MAX};
        if(a<=l && r<=b) return {node[k], moto[k]};
        return min( getmin(a,b,2*k+1,l,(l+r)/2),getmin(a,b,2*k+2,(l+r)/2,r) );
    }
};

signed main(){
    cin >> n >> m;
    cin >> s;
    REP(i,n+1) mask[i] = s[i] == '0';
    
    vi count(n+1, INT32_MAX);
    vi par(n+1, -1);
    count[0] = 0;
    SegmentTree st(count);

    REPS(i,n){
        if (!mask[i]) continue;
        auto pre = st.getmin(i-m,i);
        if (pre.first > 2*n) {
            cout << -1 << endl;
            return 0;
        }
        st.update(i, pre.first + 1);
        par[i] = pre.second;
    }

    vi ret;
    while(n > 0){
        ret.pb(n - par[n]);
        n = par[n];
    }
    for(auto it = ret.rbegin(); it != ret.rend(); it++){
        cout << *it << " ";
    }
    cout << endl;
}

Measured memory_bytes: 8176
#include<iostream>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
int R,C,K;
int v[3003][3003];
long dp[3003];
long tmp[4][3003];
main()
{
	cin>>R>>C>>K;
	for(int i=0;i<K;i++)
	{
		int r,c,va;cin>>r>>c>>va;
		r--,c--;
		v[r][c]=va;
	}
	for(int i=0;i<R;i++)
	{
		for(int j=0;j<4;j++)for(int k=0;k<C;k++)tmp[j][k]=0;
		long MX[3]={};
		for(int k=0;k<C;k++)
		{
			if(k>0)
			{
				for(int j=0;j<4;j++)tmp[j][k]=tmp[j][k-1];
			}
			MX[0]=max(MX[0],dp[k]);
			for(int j=0;j<3;j++)
			{
				tmp[j+1][k]=max(tmp[j+1][k],MX[j]+v[i][k]);
			}
			for(int j=0;j<3;j++)MX[j]=max(MX[j],tmp[j][k]);
		}
		for(int k=0;k<C;k++)
		{
			for(int j=0;j<4;j++)dp[k]=max(dp[k],tmp[j][k]);
		}
	}
	cout<<dp[C-1]<<endl;
}


Measured memory_bytes: 38796
#include<map>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mp make_pair
using namespace std;

map<pair<int,int>,int> m;
map< pair<pair<int,int>,pair<int,int> >,int> mm;

int h,w,n,x[100010],y[100010],cnt[11];

int dx1[]={-2,-2,-2,-1,-1,-1,0,0,0},dy1[]={-2,-1,0,-2,-1,0,-2,-1,0},dx2[]={0,0,0,1,1,1,2,2,2},dy2[]={0,1,2,0,1,2,0,1,2};

inline int check(int x1,int y1,int x2,int y2)
{
	if(1<=x1&&1<=y1&&x2<=h&&y2<=w)
	{
		return 1;
	}
	return 0;
}

inline void count_(int x1,int y1,int x2,int y2)
{
	int ans=9;
	for(int xx=x1;xx<=x2;xx++)
	{
		for(int yy=y1;yy<=y2;yy++)
		{
			if(m.count(mp(xx,yy))==0)
			{
				ans--;
			}
		}
	}
	cnt[ans]++;
}

inline void solve(int x,int y)
{
	for(int i=0;i<=8;i++)
	{
		int x1=x+dx1[i];
		int y1=y+dy1[i];
		int x2=x+dx2[i];
		int y2=y+dy2[i];
		if(check(x1,y1,x2,y2)&&mm.count(mp(mp(x1,y1),mp(x2,y2)))==0)
		{
			mm[mp(mp(x1,y1),mp(x2,y2))]=1;
			count_(x1,y1,x2,y2);
		}
	}
}

int main()
{
	scanf("%d%d%d",&h,&w,&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&x[i],&y[i]);
		m[mp(x[i],y[i])]=1;
	}
	for(int i=1;i<=n;i++)
	{
		solve(x[i],y[i]);
	}
	long long sum=1ll*(h-2)*(w-2);
	for(int i=1;i<=9;i++)
	{
		sum-=cnt[i];
	}
	printf("%lld\n",sum);
	for(int i=1;i<=9;i++)
	{
		printf("%d\n",cnt[i]);
	}
}

Measured memory_bytes: 63488
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

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

typedef long long ll;

int main()
{
	int n;
	double xa, ya, ra, xb, yb, rb;

	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> xa >> ya >> ra >> xb >> yb >> rb;
		
		double j = sqrt( (xb-xa)*(xb-xa) + (yb-ya)*(yb-ya) );

		if(ra + rb < j)
		{
			cout << 0 << endl;
		}
		else if(j + rb < ra)
		{
			cout << 2 << endl;
		}
		else if(j + ra < rb)
		{
			cout << -2 << endl;
		}
		else if(j + rb >= ra)
		{
			cout << 1 << endl;
		}
	}
}

Measured memory_bytes: 1232
using System;
using System.Collections.Generic;
using System.Linq;
//using System.Text;
//using System.Threading.Tasks;
using static System.Console;

namespace testConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            //var n = Array.ConvertAll(ReadLine().Split(), int.Parse);
            var s = int.Parse(ReadLine());
            var arr = new List<int>();
            arr.Add(s);

            for (var i = 1; ;i++)
            {
                var temp = arr[i - 1];

                if (temp % 2 == 0) arr.Add(temp / 2);
                else arr.Add(3 * temp + 1);

                temp = arr.Count(x => x == arr[i]);
                if (temp == 2) break;
            }

            WriteLine(arr.Count);
        }
    }
}


Measured memory_bytes: 13268
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define dup(x) x.erase(unique(x.begin(), x.end()),x.end())
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
// https://atcoder.jp/contests/abc173/tasks/abc173_b
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string ans[4] ={"AC","WA","TLE","RE"};
    ll n;
    cin >> n;
    map<string, ll> m;
    for(int i = 0;i<n;i++){
        string s;
        cin >> s;
        m[s]++;
    }
    for(auto k : ans){
        cout << k << " x " << m[k] << "\n";
    }
    

	return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i,s,e) for(i=s;i<e;i++)
#define ms(arr,val) memset(arr,val,sizeof(arr))
using namespace std;

const int mxn=2e5+1;

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

  int t=1;
//  cin>>t;
  int tt=1;
  while(t--){
    int n,m,k;
    cin>>n>>m>>k;
    if(n<m)
      swap(n,m);
    int blacks=0,moves=0;
    while(blacks<k)
    {
      blacks+=n;
      moves++;
      
   // cout<<"Case #"<<tt<<": ";
   // tt++;
    }
    cout<<moves;
    }
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, M; 
    cin >> N;
    string S[200], T[200];
    for(int i = 1; i <= N; i++){
    cin >> S[i];
    }
    int count[314]; 
    for(int i = 1; i <= N; i++){
     for(int k = 1; k <= N; k++){
    if(S[i] == S[k]) count[i]++;
     }
    }
    cin >> M;
    for(int j = 1; j <=  M; j++){
    cin >> T[j];
    }
    for(int i = 1; i <= N; i++){
     for(int l = 1; l <= M; l++){
    if(S[i] == T[l]) count[i]--;
    }
    }
    int ans = 0; 
    for(int i = 1; i <= N; i++){
    ans = max(ans, count[i]);
    }
    cout << ans << endl; 
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int b1,b2,b3;
	scanf("%d %d %d",&b1,&b2,&b3);
	if((b1==1 && b2==1) || b3==1){
		printf("Open\n");
	}else{
		printf("Close\n");
	}
	return 0;
}

Measured memory_bytes: 584
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		int K = sc.nextInt();
		long[] a = new long[x];
		long[] b = new long[y];
		long[] c = new long[z];
		for (int i = 0; i < x; i++) {
			a[i] = sc.nextLong();
		}
		for (int i = 0; i < y; i++) {
			b[i] = sc.nextLong();
		}
		for (int i = 0; i < z; i++) {
			c[i] = sc.nextLong();
		}
		sc.close();
 
		Arrays.parallelSort(a);
		Arrays.parallelSort(b);
		Arrays.parallelSort(c);

		PriorityQueue<Obj> pq = new PriorityQueue<Obj>(new Comparator<Obj>() {
			public int compare(Obj o1, Obj o2) {
				if (o1.v < o2.v) return 1;
				if (o1.v > o2.v) return -1;
				return 0;
			}
		});
		Set<Long> set = new HashSet<Long>();

		int ia = x - 1;
		int ib = y - 1;
		int ic = z - 1;
		Obj fo = new Obj(ia, ib, ic, a[ia] + b[ib] + c[ic]);
		pq.add(fo);
		long fl = ia * 10000L * 10000L + ib * 10000L + ic;
		set.add(fl);

		for (int i = 0; i < K; i++) {
			Obj obj = pq.poll();
			System.out.println(obj.v);
			ia = obj.a;
			ib = obj.b;
			ic = obj.c;
			if (ia > 0) {
				Obj o = new Obj(ia - 1, ib, ic, a[ia - 1] + b[ib] + c[ic]);
				long l = (ia - 1) * 10000L * 10000L + ib * 10000L + ic;
				if (!set.contains(l)) {
					pq.add(o);
					set.add(l);
				}
			}
			if (ib > 0) {
				Obj o = new Obj(ia, ib - 1, ic, a[ia] + b[ib - 1] + c[ic]);
				long l = ia * 10000L * 10000L + (ib - 1) * 10000L + ic;
				if (!set.contains(l)) {
					pq.add(o);
					set.add(l);
				}
			}
			if (ic > 0) {
				Obj o = new Obj(ia, ib, ic - 1, a[ia] + b[ib] + c[ic - 1]);
				long l = ia * 10000L * 10000L + ib * 10000L + (ic - 1);
				if (!set.contains(l)) {
					pq.add(o);
					set.add(l);
				}
			}
		}
	}

	static class Obj {
		int a, b, c;
		long v;
		Obj(int a, int b, int c, long v) {
			this.a = a;
			this.b = b;
			this.c = c;
			this.v = v;
		}

		public boolean equals(Object obj) {
			Obj o = (Obj) obj;
			if (this.a == o.a && this.b == o.b && this.c == o.c && this.v == o.v) {
				return true;
			}
			return false;
		}

		public String toString() {
			return this.a + " " + this.b + " " + this.c + " " + this.v;
		}
	}
}


Measured memory_bytes: 29236
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
using namespace std;


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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

vector<ll> ans(10,0);

set<pii> pts;

int R,W;

void solvex(int x, int y){
	
	int cnt;

	for(int i = max(x - 2,0); i < min(x + 3,R) - 2; i++){
		for(int j = max(y - 2,0); j < min(y + 3,W) - 2; j++){

			cnt = 0;

			for(int k = i; k < i + 3; k++){
				for(int l = j; l < j + 3; l++){
					if(pts.count({k,l})) cnt++;
				}
			}

			ans[cnt]++;
		}
	}
	
}

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

	int N;
	cin >> R >> W >> N;

	for(int i = 0; i < N; i++){
		int x,y;
		cin >> x >> y;
		x--;y--;

		pts.insert({x,y});
	}
	
	for(auto pp : pts){
		solvex(pp.f, pp.s);
	}

	int cnt = 0;

	for(int i = 1; i < 10; i++){
		ans[i] /= i;
		cnt += ans[i];
	}

	ans[0] = (ll)(R-2)*(W-2) - cnt;

	for(int i = 0; i < 10; i++) cout << ans[i] << endl;


	return 0;
}


Measured memory_bytes: 8312
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll
typedef vector<int> vi;
typedef pair<int,int> pii;

signed main(void) {
  int i,j;
  string s;
  cin>>s;
  vi num(26,0);
  int n=s.size();
  ll ans=(ll)n*(n-1)/2+1;
  rep(i,n)num[s[i]-'a']++;
  rep(i,26)if(num[i])
    ans-=num[i]*(num[i]-1)/2;
  cout<<ans<<endl;
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

int mp[250011];

int main(){

  REP(i,250011)mp[i] = -1;

  int n;cin >> n;
  vector<pair<int,int>> v;

  REP(i,n){
    int tmp;cin >> tmp;
    tmp--;
    v.PB(MP(tmp,i+1));
    if(mp[tmp] != -1){
      cout << "No" << endl;
      return 0;
    }
    mp[tmp] = i+1;
  }

  sort(ALL(v));
  int cou = 0;

  REP(i,n){
    REP(j,v[i].SE-1){
      while(mp[cou] != -1)cou++;
      mp[cou] = v[i].SE;
      if(cou > v[i].FI){
        cout << "No" << endl;
        return 0;
      }
      cou++;
    }
  }

  REP(i,n){
    for(int j = v[i].SE + 1;j <= n;j++){
      while(mp[cou] != -1)cou++;
      if(cou < v[i].FI){
        cout << "No" << endl;
        return 0;
      }
      mp[cou] = v[i].SE;
      cou++;
    }
  }

  cout << "Yes" << endl;
  REP(i,n*n)cout << mp[i] << " ";
  cout << endl;



	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int n, ans;
  cin >> n;
  int h[n];
  for(int i=0;i<n;++i) cin >> h[i];

  //operation
  ans = h[0];
  for(int i=1;i<n;++i){
    if(h[i-1] <= h[i])
      ans += h[i]-h[i-1];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
def main():
    a, b, k = (int(s) for s in input().split())
    if a >= k:
        print(a - k, b)
        return
    else:
        a, k = 0, k - a
        if b >= k:
            print(a, b - k)
            return
        else:
            print(0, 0)
            return

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll H, N;
  cin >> H >> N;

  vector<ll> damages(H + 1, -1);
  damages[0] = 0;

  unordered_map<ll, ll> damage_mp;

  rep (i, N) {
    ll a, b;
    cin >> a >> b;
    if (damage_mp.count(a) == 0) damage_mp[a] = b;
    else damage_mp[a] = min(damage_mp[a], b);
  }

  ll ans = -1;

  for (ll i = 0; i < H; i++) {
    if (damages[i] == -1) continue;
    for (auto it: damage_mp) {
      ll next_damage = i + it.first;
      ll next_mp = damages[i] + it.second;
      if (next_damage < H) {
        if (damages[next_damage] == -1) damages[next_damage] = next_mp;
        else damages[next_damage] = min(damages[next_damage], next_mp);
      } else {
        if (ans == -1) ans = next_mp;
        else ans = min(ans, next_mp);

      }
    }
  }

  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 384
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

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

typedef long long value; // 格納するデータの型
const value INIT = 0ll; // 初期値．目的に応じて，適切な値に変更すること．

class segment_tree {
private:
	int n;
	vector<value> dat;

	value func(value a, value b) const { // ノードの値を決める為の関数
		return max(a, b);
	}

	value query(int a, int b, int k, int l, int r) const {
		if(r <= a || b <= l) // 求める区間が，ノードの区間と重なっていない．
			return INIT;

		if(a <= l && r <= b) { // 求める区間が，ノードの区間を完全に含む．
			return dat[k];
		}
		else {
			const int mid = (l + r) / 2;
			const value vl = query(a, b, k * 2 + 1, l, mid);
			const value vr = query(a, b, k * 2 + 2, mid, r);
			return func(vl, vr);
		}
	}

public:
	segment_tree(int n_) {
		n = 1;
		while(n < n_)
			n *= 2;

		dat.resize(2 * n, INIT);
	}

	void update(int k, value a) { // k番目の要素をaに更新する．
		k += n - 1;
		dat[k] = a;
		while(k > 0) {
			k = (k - 1) / 2;
			dat[k] = func(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}

	value query(int a, int b) { // [a, b)に対するクエリ
		return query(a, b, 0, 0, n);
	}
};

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

	int m;
	cin >> m;

	segment_tree segt(m);

	long long mx = 0;
	for(int i = 0; i < m; ++i) {
		int w;
		cin >> w;

		long long tmp = segt.query(1, w) + w;
		segt.update(w, tmp);
		chmax(mx, tmp);
	}

	cout << ((m + 1ll) * m / 2ll - mx) << endl;
	return EXIT_SUCCESS;
}

Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <unordered_map>


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

  std::vector<int> a(N);
  for(int i=0; i<N; i++) std::cin >> a[i];

  std::sort(a.begin(), a.end(), [](int x, int y) { return x > y; });

  int alice = 0, bob = 0;
  for(int i=0; i<N; i++){
    if ( i % 2 == 0 ) alice += a[i];
    else bob += a[i];
  }
  std::cout << alice - bob << std::endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int N = Integer.parseInt(in.next());
            String A = in.next();
            String B = in.next();
            String C = in.next();
            int ans = 0;

            for (int i = 0; i < N; i++) {
                if (A.charAt(i) != B.charAt(i) && B.charAt(i) != C.charAt(i) && C.charAt(i) != A.charAt(i)) {
                    ans += 2;
                } else if ((A.charAt(i) == B.charAt(i) && B.charAt(i) != C.charAt(i)) ||
                        (B.charAt(i) == C.charAt(i) && C.charAt(i) != A.charAt(i)) ||
                        (A.charAt(i) == C.charAt(i) && A.charAt(i) != B.charAt(i))) {
                    ans += 1;
                }
            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000000000000ll
using namespace std;
map<ll, ll>mem;
ll a, b, c, d;
ll dp(ll n)
{
    if(n==0)return 0ll;
    if(n==1ll)return d;
    if(mem.find(n)!=mem.end())return mem[n];

    ll ret= inf, x;
    if(n<(inf/d))ret= n*d;

    x= (n/2ll)*2ll;
    ret= min(ret, (n-x)*d+a+dp(x/2));
    if(n%2ll)
    {
        x= ((n/2ll)+1)*2ll;
        ret= min(ret, (x-n)*d+a+dp(x/2));
    }

    x= (n/3ll)*3ll;
    ret= min(ret, (n-x)*d+b+dp(x/3ll));
    if(n%3ll)
    {
        x= ((n/3ll)+1)*3ll;
        ret= min(ret, (x-n)*d+b+dp(x/3ll));
    }

    x= (n/5ll)*5ll;
    ret= min(ret, (n-x)*d+c+dp(x/5ll));
    if(n%5ll)
    {
        x= ((n/5ll)+1)*5ll;
        ret= min(ret, (x-n)*d+c+dp(x/5ll));
    }
    return mem[n]= ret;
}
int main()
{
    int ts;
    scanf("%d", &ts);
    while(ts--)
    {
        mem.clear();
        ll n;
        scanf("%lld %lld %lld %lld %lld", &n, &a, &b, &c, &d);
        printf("%lld\n", dp(n));
    }
    return 0;
}


Measured memory_bytes: 4660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<double> VL;
typedef vector<string> VS;
typedef vector<PLL> VP;
typedef vector<ll> VLL;
const static int INF = 1000000000;
const static int MOD = 1000000007;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<ll> a, vector<ll> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    int N;
    cin >> N;
    VLL a(N);
    ll X=0;
    rep(i,N){
        cin >> a[i];
        X+=a[i];
    } 
    ll x=0;
    ll ans=10000000000;
    rep(i,N){
        x+=a[i];
        if(i+1<N){
            ans=min(ans,abs(X-2*x));
        }
    }
    cout << ans << endl;
}


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

int main()
{
    int o25, o5, unu, doi, n;
    cin >> o25 >> o5 >> unu >> doi >> n;
    o5 = min(o5, 2 * o25);
    unu = min(unu, 2 * o5);
    doi = min(doi, 2 * unu);
   // unu = min(unu, doi);

    cout << 1ll * (n / 2) * doi + 1ll * (n & 1) * unu;
    return 0;
}


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



int main() {
  int N;
  cin>>N;
  
  int T,A;
  cin>>T>>A;
  
  double a=100000;
  double b;
  double c;
  double d;
  
  vector<double> H(N);
for (int i = 0; i < N; i++) {
  cin >> H.at(i);
}
  
  for(int i=0;i<N;i++){
    
    b=T-H.at(i)*0.006;
   // cout<<b<<endl;
    if(b>A){
      c=b-A;
    }
    else{
      c=A-b;
    }
   // cout<<c<<endl;
    a=min(a,c);
  //  cout<<a<<endl;
    if(a==c){
      d=i;
      
     // cout<<d<<endl;
    }
  }
  
  cout<<d+1<<endl;

  
  
}






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

using namespace std;

int main() {
    int n;
    cin >> n;
    int arr[n][2];
    for (int i = 0; i < n; ++i) {
        cin >> arr[i][0] >> arr[i][1];
    }
    for (int i = 0; i < n-2; ++i) {
        if (arr[i][0] == arr[i][1] && arr[i+1][0] == arr[i+1][1] && arr[i+2][0] == arr[i+2][1]) {
            cout << "Yes";
            return 0;
        }
    }

    cout << "No";
}

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

int main() {
  int N;
  cin >> N;
  double p[N+1], dp[N+1][N+1] = {};
  for (int i=1; i<=N; i++) cin >> p[i];
  dp[0][0] = 1;
  for (int i=1; i<N; i++) {
    int j=0;
    dp[i][j] = dp[i-1][j] * (1-p[i]);
  }
  for (int i=1; i<=N; i++) {
    for (int j=1; j<=i; j++) {
      dp[i][j] = dp[i-1][j-1] * p[i] + dp[i-1][j] * (1-p[i]);
    }
  }
  double ans = 0;
  for (int j=(N+1)/2; j<=N; j++) ans += dp[N][j];
  cout << setprecision(10) << ans << endl;
}


Measured memory_bytes: 70528
import sys
import math
import bisect
# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
MOD = 10 ** 9 + 7


# ===CODE===

k = int(input())
a,b = map(int,input().split())

for i in range(a,b+1):
    if i%k==0:
        print("OK")
        exit(0)

print("NG")

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
int main() 
{
     fast;
     int n;
     cin>>n;
     int a[n+1][3];
     int dp[n+1][3];
     ffor(i,0,n)
     ffor(j,0,3)
     cin>>a[i][j];
     dp[0][0]=a[0][0];
     dp[0][1]=a[0][1];
     dp[0][2]=a[0][2];
     ffor(i,1,n)
     ffor(j,0,3)
     {
       dp[i][j]=a[i][j]+max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
     }
     int ans=dp[n-1][0];
     ffor(i,1,3)
     ans=max(ans,dp[n-1][i]);
     cout<<ans;
    //  ffor(i,0,n)
    //  {ffor(j,0,3)
    //  cout<<dp[i][j]<< " ";
    //  cout<<endl;}
}


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

// #undef DEBUG
// #define DEBUG
/// {{{ DEBUG --- ///
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { if(&o == &cerr) { o << '{'; for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? ", " : ""); o << "}"; } else { for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? " " : ""); } return o; }
#ifdef DEBUG
#define dump(...) cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n";
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
#else
#define dump(...)
#endif
/// }}}--- ///

vector<int> B(2010);
vector<int> W(2010);
vector< vector<int> > dB(2010, vector<int>(2010)); // w, b
vector< vector<int> > dW(2010, vector<int>(2010)); // b, w
int dp[2010][2010]; // w, b

/// --- BIT Library {{{ ///

struct BIT{
  vector<ll> data;
  int n;
  BIT(int n): n(n){
    data.resize(n, 0);
  }
  void clear(int sz=0) {
    if(sz > 0) n = sz;
    data.assign(n, 0);
  }
  void add(int i, ll x) {
    i++;
    while(i<=n){
      data[i-1] += x;
      i += i&-i;
    }
  }
  ll sum(int i) {
    if(i<0) return 0;
    i++;
    ll s = 0;
    while(i>0){
      s += data[i-1];
      i -= i&-i;
    }
    return s;
  }
  ll range(int a, int b) {
    return sum(b) - sum(a-1);
  }
};

/// }}}--- ///

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  for(int i = 0; i < n * 2; i++) {
    char c; int x;
    cin >> c >> x;
    x--;
    if(c == 'B') {
      B[x] = i;
    } else {
      W[x] = i;
    }
  }
  for(int _ = 0; _ < 2; _++) {
    for(int b = 0; b <= n; b++) {
      BIT bit(n * 2 + 10);
      for(int i = 0; i < b; i++) {
        bit.add(B[i], 1);
      }
      for(int w = 0; w < n; w++) {
        dW[b][w] = bit.sum(W[w]);
        bit.add(W[w], 1);
      }
    }
    swap(dW, dB);
    swap(W, B);
  }
  for(int i = 0; i <= n; i++)
    for(int j = 0; j <= n; j++) dp[i][j] = 1e9;
  dp[0][1] = B[0] - dB[0][0];
  dp[1][0] = W[0] - dW[0][0];
  for(int i = 1; i <= n * 2 - 1; i++) {
    for(int j = 0; j <= min(i, n); j++) {
      int k = i - j;
      if(k > n) continue;
      int w = dp[j + 1][k];
      int b = dp[j][k + 1];
      w = min(w, dp[j][k] + W[j] - dW[k][j]);
      b = min(b, dp[j][k] + B[k] - dB[j][k]);
      dp[j + 1][k] = w;
      dp[j][k + 1] = b;
    }
  }
  cout << dp[n][n] << endl;
}


Measured memory_bytes: 47744
#include <iostream>
#include <climits>
#include <unordered_map>
#include <string>

uint32_t ASCII_SUB = 65;

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

  uint64_t N;
  std::cin >> N;

  const std::string MARCH("MARCH");
  std::unordered_map<char, uint64_t> m;

  for (uint64_t i = 0; i < N; i++) {
    std::string S;
    std::cin >> S;
    auto cur = S[0];
    if (cur == 'M' || cur == 'A' || cur == 'R' || cur == 'C' || cur == 'H') {
      m[cur]++;
    }
  }

  uint64_t found = 0;
  for (uint64_t i = 0; i < 5; i++) {
    for (uint64_t j = i + 1; j < 5; j++) {
      for (uint64_t k = j + 1; k < 5; k++) {
        found += m[MARCH[i]] * m[MARCH[j]] * m[MARCH[k]];
      }
    }
  }

  std::cout << found << std::endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		long ans=0;
		for(int i=1;i<=n;i++) {
			if(i%3==0 || i%5==0 ) {
				continue;
			}
			ans+=i;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 27168
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
long long int fie[1001][1001];
int main(){
    int N,M;
    cin>>N>>M;
    int city[1001],weather[1001];
    for(int i=0;i<N;i++)cin>>city[i];
    for(int i=0;i<M;i++)cin>>weather[i];
    for(int i=0;i<1001;i++){
        for(int j=0;j<1001;j++){
            fie[i][j]=1000000000000000;
        }
    }
    fie[0][0]=0;
    for(int i=1;i<M+1;i++){
        for(int j=0;j<N+1;j++){
            if(j!=0)fie[i][j]=min(fie[i][j],min(fie[i-1][j],fie[i-1][j-1]+city[j-1]*weather[i-1]));
            else fie[i][j]=min(fie[i][j],fie[i-1][j]);
        }
    }
    cout<<fie[M][N]<<endl;
    return 0;
}

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

using namespace std;

template<class T>
T read()
{
    T value;
    std::cin >> value;
    return value;
}
 
template<class F>
void times_do(size_t n, F func)
{
    for(size_t i = 0; i < n; ++i) func();
}
 
template<class T>
vector<T> reads(size_t n)
{
    vector<T> a;
    a.reserve(n);
    times_do(n, [&](){
        a.push_back(read<T>());
    });
    return a;
}

int main(){
    const size_t n = read<size_t>();
    auto a = reads<size_t>(n);

    sort(begin(a), end(a), std::greater<size_t>());
    
    vector<size_t> selected;
    
    for(size_t i = 0; i < a.size() - 1; ++i){
        if(a[i] == a[i+1]){
            selected.push_back(a[i]);
            ++i;
        }
    }
    
    if(selected.size() >= 2){
        cout << (selected[0] * selected[1]) << endl;
    }else{
        cout << '0' << endl;
    }

    return 0;
}


Measured memory_bytes: 1660
// package app;

import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);

        // final String N = sc.next();
        final int A = sc.nextInt();
        final int B = sc.nextInt();
        final int C = sc.nextInt();
        // final int N = sc.nextInt();
        // final int D = sc.nextInt();
        // System.out.println();
        int result = 0;
        if (A == B){
            result = C;
        } else if(A == C) {
            result = B;
        } else {
            result = A;
        }

        System.out.println(result);

        // System.out.println(A <= X && A + B >= X ? "YES" : "NO");

    }
}

Measured memory_bytes: 21844
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
// using namespace atcoder;
using ll = long long;
const ll mod = 1e9 + 7;

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(all(a));
    sort(all(b));
    sort(all(c));
    ll ans = 0;
    rep(i, n)
    {
        ll up = lower_bound(all(a), b[i]) - a.begin();
        ll lp = c.end() - upper_bound(all(c), b[i]);
        ans += up * lp;
    }
    cout << ans << endl;
}

int main()
{
    // srand((unsigned)time(NULL));
    // int t = clock();
    solve();
    // double et = 1.0 * (clock() - t) / CLOCKS_PER_SEC;
    // printf("Execution Time: %.4lf sec\n", et);
    return 0;
}

Measured memory_bytes: 4588
#include <algorithm>
#include <cstdio>
#include <set>
#define ALL(x) (x).begin(), (x).end()
const int MAXM = 3e5+5;
std::multiset<int> here, next, prev;
int M, N, S;

bool solve() {
  auto big = here.begin();
  next.insert(*big);
  here.erase(big);
  for (int i = 0; i < N; ++i) {
    prev = std::move(next);
    for (auto j: prev) {
      auto ptr = here.upper_bound(j);
      if (ptr == here.end()) {
        return false;
      }
      next.insert(j);
      next.insert(*ptr);
      here.erase(ptr);
    }
  }
  return true;
}

int main() {
  scanf("%d", &N);
  M = 1 << N;
  for (int i = 0; i < M; ++i) {
    scanf("%d", &S);
    here.insert(-S);
  }
  puts(solve() ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 18744
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    string s, t;
    cin >> s;
    for (char i : s) {
        if(i == '1') t += "9";
        else if(i == '9') t += "1";
        else t += i;
    }
    cout << t << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

int alpha2int(char c) {
  if (isupper(c)) return c-'A'+26;
  else return c-'a';
}
char int2alpha(int i) {
  if (i<26) return 'a'+i;
  else return 'A'+i-26;
}

int main() {
  int n;
  while(cin >> n, n) {
    int k[n];
    REP(i,n) cin >> k[i];
    string s; cin >> s;
    REP(i,s.size()) {
      s[i] = int2alpha((alpha2int(s[i])+52-k[i%n])%52);
    }
    cout << s << endl;

  }
}

Measured memory_bytes: 1204