akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      res.push_back(i);
      if(i!=n/i)res.push_back(n/i);
    }
  }
  return res;
}

ll n;

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

  cin>>n;
  vector<ll> ds=divisor(n);
  sort(all(ds)); uni(ds);

  ll res=0;
  rep(i,ds.size()){
    ll k=ds[i];
    ll m=(n/k)-1;
    if(k<m)res+=m;
  }
  cout<<res<<endl;

  return 0;
}


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

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

    bool flag1 = true;
    for(int i = 0; i < n/2; i++) {
        if(s[i] != s[n - i - 1]) {
            flag1 = false;
            break;
        }
    }

    bool flag2 = true;
    for(int i = 0; i < (n - 1)/4; i++) {
        if(s[i] != s[(n - 1)/2 - i - 1]) {
            flag2 = false;
            break;
        }
    }

    cout << ((flag1 && flag2) ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << -1; return;}

void solve() {
    int n, ans = 0; 
    cin >> n;
    vector <int> a(n), used(n);
    loop(i, n)
        cin >> a[i];
    loop1(step, n - 2) {
        int sum = 0;
        for (int i = step; n - 1 - i > step && i != n - 1 - i && used[i] != step && used[n - i - 1] != step; i += step) {
            sum += a[i] + a[n - 1 - i];
            used[i] = used[n - i - 1] = step;
            ans = max(ans, sum);
        }
    }
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

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

#define N 10

using namespace std;

void check(int x,int y,int c,int b[N][N],int f[N][N],int n){
  if(x<0 || y<0) return;
  if(x>y || y>=n) return;

  if(b[y][x]==c && f[y][x]==0){
    f[y][x]=1;
    check(x-1,y-1,c,b,f,n);
    check(x  ,y-1,c,b,f,n);
    check(x-1,y  ,c,b,f,n);
    check(x+1,y  ,c,b,f,n);
    check(x ,y+1,c,b,f,n);
    check(x+1,y+1,c,b,f,n);
  }
}

int main(){
  int b[N][N];
  int n,c;

  while(cin >> n >> c, n+c){
    vector<pair<int,int> > zero;
    for(int i=0;i<n;i++){
      for(int j=0;j<=i;j++){
	cin >> b[i][j];
	if(b[i][j]==0)
	  zero.push_back(make_pair(i,j));
      }
    }

    int ans=-1000;

    if(zero.empty()) ans=0;

    for(int z=0;z<zero.size();z++){
      int x,y;
      int f[N][N]={{0}};

      y=zero[z].first; x=zero[z].second;

      b[y][x]=c;

      /*
      cout << "[board]" << endl;
      for(int i=0;i<n;i++){
	for(int j=0;j<=i;j++){
	  cout << b[i][j] << " ";
	}
	cout << endl;
      }
      */

      for(int zz=0;zz<zero.size();zz++){
	int x,y;
	if(zz==z) continue;
	y=zero[zz].first; x=zero[zz].second;
	check(x-1,y-1,b[y-1][x-1],b,f,n);
	check(x  ,y-1,b[y-1][x  ],b,f,n);
	check(x-1,y  ,b[y  ][x-1],b,f,n);
	check(x+1,y  ,b[y  ][x+1],b,f,n);
	check(x  ,y+1,b[y+1][x  ],b,f,n);
	check(x+1,y+1,b[y+1][x+1],b,f,n);
      }

      /*
      cout << "[flag]" << endl;
      for(int i=0;i<n;i++){
	for(int j=0;j<=i;j++){
	  cout << f[i][j] << " ";
	}
	cout << endl;
      }
      cout << endl;
      */

      int count=0;
      for(int i=0;i<n;i++){
	for(int j=0;j<=i;j++){
	  if(f[i][j]==0){
	    if(b[i][j]==0)
	      continue;
	    else if(b[i][j]==c)
	      count--;
	    else
	      count++;
	  }
	}
      }
      ans = max(ans,count);

      b[y][x]=0;
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

typedef long long i64;

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    vector<int> A(n), B(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i] >> B[i];
    }

    int64_t add = 0;
    for (int i = n - 1; i >= 0; --i) {
        if ((A[i] + add) % B[i] != 0) {
            int64_t c = (A[i] + add) / B[i] + 1;
            c = B[i] * c - A[i] - add;
            add += c;
        }
    }
    cout << add << '\n';
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
long long t;
int a[4];
int gcd(int x, int y, int z)
{
    int s=min(x, min(y, z));
    while (x%s!=0||y%s!=0||z%s!=0) s--;
    return s;
}
int main()
{
    int k;
    cin >> k;
    a[1]=1, a[2]=1, a[3]=1;
    while (a[0]==0)
    {
        a[3]++;
        int i=3;
        while (a[i]>k)
        {
            a[i]=1;
            i--;
            a[i]++;
        }
        t+=gcd(a[1], a[2], a[3]);
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 3596
/*
Author : Devil088
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define sep cout<<"\n";
#define Yes cout<<"Yes\n";
#define No cout<<"No\n";
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
int main(){
	long N;
	cin>>N;
	long x,m = 0,n = 10000000000;
	for(int i=0;i<N;i++){
		cin>>x;
		m = max(x,m);
		n = min(x,n);
	}
	
	cout<<m-n<<"\n";
}
/*
10
3 3 3 3 3 1 3 3 3 3 3 
0 1 2 3 4 5 6 7 8 9 10
* 
* 
8 3
7 3 1 1 1 1 2 5
3 5 2 3 4 1
0 1 2 3 4 5 6 7
* */


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

using namespace std;
typedef long long int ll;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

const int INF = 7368791;
int P[INF + 1];

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  while (true) {
    int M, N; cin >> M >> N;
    if (N == 0 and M == 0) break;
    memset(P, 0, sizeof(P));

    for (int i = M, cnt = 0; ; i++) {
      if (not P[i]) {
        if (cnt == N) {
          cout << i << endl;
          break;
        }
        for (int j = i; j <= INF; j += i) P[j] = 1;
        cnt++;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 31988
#define ll long long int

#include <bits/stdc++.h>

using namespace std;

int main() {

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

    return 0;
}

Measured memory_bytes: 3816
import sys
input = sys.stdin.readline
ri = lambda: int(input())
#rl = lambda: [int(x) if x.isdecimal() else x for x in input().split()]
#rl = lambda: list(input().split()))
rl = lambda: map(int,input().split())
rr = lambda N: [list(l) for l in zip(*[rl() for _ in range(N)])]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD = 10**9+7

L = input().rstrip('\n')
N = len(L)

dp = [[0 for smaller in range(2)] for k in range(N+1)]
dp[0][0] = 1
for i in range(1,N+1):
    if L[i-1] == '1':
        dp[i][0] = dp[i-1][0]*2 % MOD
        dp[i][1] = (dp[i-1][0] + dp[i-1][1] *3) % MOD
    elif L[i-1] == '0':
        dp[i][0] = dp[i-1][0] % MOD
        dp[i][1] = dp[i-1][1]*3 % MOD

print((dp[N][0]+dp[N][1])%MOD)




Measured memory_bytes: 21256
#include <iostream>
#include <ctime>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <chrono>
#include <stack>
#include <cassert>
#include <queue>
#include <deque>
#include <climits>
#include <cstring>
#include <random>
#include <bitset>

using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    #ifdef LOCAL
    assert(freopen("input.txt", "r", stdin));
    assert(freopen("output.txt", "w", stdout));
    #endif
    
    int x, y;
    cin >> x >> y;
    cout << x + y / 2 << endl;
}


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

using namespace std;


int main() {
    int A, B, C; cin >> A >> B >> C;
    if (A < B) {
        if (A <= C && C <= B) cout << "Yes" <<endl;
        else cout << "No" << endl;
    } else {
        if (B <= C && C <= A) cout << "Yes" <<endl;
        else cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main( )
{
	int n,k,sum=0;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<k;i++){
		sum+=a[i];
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const ll mod =1000000007;
ll gcd(ll a, ll b){
    if(a<b) swap(a,b);
    while(b>0){
        ll p= a%b;
        a = b;
        b=p;
    }
    return a;
}
ll lcm(ll a, ll b){
    ll g = gcd(a,b);
    return (a/g) * b;
}
int main(){
    long long  n,m;
    cin>>n>>m;
    vector<long long> v(n);
    ll l=1;
    for(int i=0; i<n; i++){
        cin>>v.at(i);
        l=lcm(l, (v.at(i)/2 ) );
        if(l>m){
            l = m+1;
        }
    }
    ll ans = m/l;
    ll kai=2;
    ll tl =l;
    if(tl<=m){
        while(tl%2 ==0){
            kai *=2;
            tl /=2;
        }
    }
    bool ok = true;
    for(int i=1; i<n; i++){
        ll a=v.at(i);
        if((a/kai) %2 ==0) ok =false;
    }
    cout<<(ok? (ans+1)/2 : 0)<<endl;
}

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

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back
#define DEBUG(x) cout << #x << " = " << x << endl;

using namespace std;

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

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> inline T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

inline void proc_status ()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) << endl;
}

const int Maxn = 2e5 + 100;

int N, M, K;
pii A[Maxn];
map <pii, int> Map;
vector <int> vec[Maxn];

inline int Check (int t, int x, int y)
{
	for (int i = 0; i < vec[t].size(); ++i)
		if (x <= vec[t][i] && vec[t][i] <= y) return 1;
	return 0;
}

inline void Solve ()
{
	int pos = 1;
	for (int i = 1; i <= N; ++i)
	{
		if (Check (i + 1, 1, pos))
		{
			cout << i << endl;
			return ;
		}

		if (!Map[mp (i + 1, pos + 1)]) ++pos;
	}

}

inline void Input ()
{
	N = read<int>(), M = read<int>(), K = read<int>();
	for (int i = 1; i <= K; ++i)
	{
		A[i].x = read<int>(), A[i].y = read<int>();
		Map[mp (A[i].x, A[i].y)] = 1;
		vec[A[i].x].pb (A[i].y);
	}
	for (int i = 1; i <= N; ++i) vec[N + 1].pb (i), Map[mp (N + 1, i)] = 1;
}

int main()
{

#ifdef hk_cnyali
	freopen("D.in", "r", stdin);
	freopen("D.out", "w", stdout);
#endif

	Input ();
	Solve ();

	return 0;
}


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

struct ftree {
  vector<int> bit;
  void update(int x, int val) {
    while (x < (int)bit.size()) {
      bit[x] = max(bit[x], val);
      x += x&-x;
    }
  }

  int query(int x) {
    int ret=0;
    while (x > 0) {
      ret = max(ret, bit[x]);
      x -= x&-x;
    }
    return ret;
  }
};

int32_t main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);

  int n;
  cin >> n;

  ftree bit;
  bit.bit.resize(n + 5, 0);
  
  vector<pair<pair<int, int>,int>> f(n);
  for (int i = 0; i < n; ++i) {
    cin >> f[i].first.first;
  }
  for (int i = 0; i < n; ++i) {
    cin >> f[i].first.second;
    f[i].second = i + 1;
  }
  
  int ans = 0;
  sort(f.begin(), f.end());
  for (int i = 0; i < n; ++i) {
    int val = bit.query(f[i].second);
    ans = max(ans, val + f[i].first.second);
    bit.update(f[i].second, val + f[i].first.second);
  }
  cout << ans << '\n';
}


Measured memory_bytes: 9524
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

class UnionFind {
public:
	vector<int> Parent;

	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	int root(int A) {
		if (Parent[A] < 0)return A;
		return Parent[A] = root(Parent[A]);
	}

	int size(int A) {
		return -Parent[root(A)];
	}

	bool unite(int A, int B) {
		A = root(A);
		B = root(B);
		if (A == B)
			return false;

		if (size(A) < size(B))
			swap(A, B);

		Parent[A] += Parent[B];
		Parent[B] = A;

		return true;
	}

	bool same(int A, int B) {
		if (root(A) == root(B))
			return true;
		else
			return false;
	}
};

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

	int N, M;
	cin >> N >> M;
	int n = N-1;
	
	UnionFind uni(N);
	vector<pii>A;
	REP(i, N) {
		int a;
		cin >> a;
		A.push_back(pii(a, i));
	}
	SORT(A);
	vector<VI>G(N);
	REP(i, M) {
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	vector<bool>vis(N, false);
	REP(i, N) {
		if (vis[i])continue;

		queue<int>Q;
		Q.push(i);
		
		while (!Q.empty()) {
			int a = Q.front();
			Q.pop();
			vis[a] = true;
			if (i != a)uni.unite(i, a);
			
			REP(j, G[a].size()) {
				if (!vis[G[a][j]]) {
					Q.push(G[a][j]);
					n--;
				}
			}
		}

	}
	if (n*2>N) {
		cout << "Impossible" << endl;
		return 0;
	}
	int R = uni.root(0);
	bool f = true;
	REP(i, N) {
		if (uni.root(i) != R) {
			f = false;
			break;
		}
	}
	if (f) {
		cout << 0 << endl;
		return 0;
	}


	int ans = 0, cnt = 0;
	map<int, int>mp;
	vector<bool> used(N, false);
	priority_queue<int, vector<int>, greater<int> > Q;


	for(auto i:A){
		if (mp[uni.root(i.second)] == 0) {
			ans += i.first;
			mp[uni.root(i.second)]++;
			used[i.second] = true;
			cnt++;

			//cout << i.second << endl;
		}
	}
	for (auto i : A) {
		if (cnt == n * 2)break;
		if (!used[i.second]&&mp[uni.root(i.second)]<n) {
		//if (!used[i.second]) {
			ans += i.first;
			mp[uni.root(i.second)]++;
			cnt++;

			//cout << i.second << endl;

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



Measured memory_bytes: 10224
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    StringBuilder aa = new StringBuilder(a);
    StringBuilder bb = new StringBuilder(b);
    StringBuilder cc = new StringBuilder(c);
    char x = aa.charAt(0);
    String ans = "";
    while (true) {
      if (x == 'a') {
        if (aa.length() == 0) {
          ans = "A";
          break;
        } else {
        x = aa.charAt(0);   
        aa.delete(0,1);
        }
      }
      if(x == 'b') {
        if (bb.length() == 0) {
          ans = "B";
          break;
        } else {
        x = bb.charAt(0); 
        bb.delete(0,1);
        }
      }
      if(x == 'c') {
        if (cc.length() == 0) {
          ans = "C";
          break;
        } else {
        x = cc.charAt(0); 
        cc.delete(0,1);
        }
      }
    }

    System.out.println(ans);
    
  }
}

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

int main() {
  long n;
  cin >> n;
  
  long ans;
  
  long m = sqrt(n)/1;
  
  for(long i=m; i>0; i--){
    if(n%i==0){
      long j = n/i;
      ans = i + j - 2;
      cout << ans << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
from itertools import accumulate


class Combination:
    def __init__(self, N, MOD=10 ** 9 + 7):
        self.MOD = MOD
        self.fact, self.inv = self._make_factorial_list(N)

    def __call__(self, n, k):
        if k < 0 or k > n:
            return 0
        res = self.fact[n] * self.inv[k] % self.MOD
        res = res * self.inv[n - k] % self.MOD
        return res

    def _make_factorial_list(self, N):
        fact = [1] * (N + 1)
        inv = [1] * (N + 1)
        MOD = self.MOD
        for i in range(1, N + 1):
            fact[i] = (fact[i - 1] * i) % MOD
        inv[N] = pow(fact[N], MOD - 2, MOD)
        for i in range(N, 0, -1):
            inv[i - 1] = (inv[i] * i) % MOD
        return fact, inv


if __name__ == "__main__":
    N, K = map(int, input().split())
    MOD = 10**9+7
    comb = Combination(2*10**5+5, MOD)

    ans = []
    for i in range(min(N - 1, K) + 1):
        val = comb(N, i) * comb(N - 1, i) % MOD
        ans.append(val)

    answer = 0
    while ans:
        answer = (answer + ans.pop()) % MOD
    print(answer)


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    int A[N]; rep(i, N) cin >> A[i];
    int cnt[N]; rep(i, N) cnt[i] = A[i]-1;
    queue<int> ans;
    rep(a, N){
        bool ok = false;
        for(int i = N-1; i >= 0; i--){
            if(cnt[i] == 0){
                ok = true;
                ans.push(A[i]);
                for(int j = i; j < N; j++) cnt[j]--;
                break;
            }
        }

        if(!ok){
            cout << -1 << endl;
            return 0;
        }
    }
    rep(i, N){
        cout << ans.front() << endl;
        ans.pop();
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define inf (long long int)(1e18)

typedef struct {
	long long int nextver;
	long long int c;
}edge;

typedef struct {
	long long int score;
	long long int nextnum;
	edge *nexts;
}vertex;

long long int max(long long int a, long long int b){
	if(a > b){
		return a;
	}
	else{
		return b;
	}
}

long long int main(){
	long long int N, M, a, b, c, i, j, k;
	scanf("%lld%lld", &N, &M);
	vertex *ver = (vertex *)malloc(sizeof(vertex) * N);
	for(i = 0; i < N; i++){
		ver[i].score = -inf;
		ver[i].nextnum = 0;
		ver[i].nexts = (edge *)malloc(sizeof(edge) * N);
	}
	ver[0].score = 0;
	for(i = 0; i < M; i++){
		scanf("%lld%lld%lld", &a, &b, &c);
		ver[a - 1].nexts[ver[a - 1].nextnum].nextver = b - 1;
		ver[a - 1].nexts[ver[a - 1].nextnum].c = c;
		ver[a - 1].nextnum++;
	}
	for(k = 0; k < N; k++){
		for(i = 0; i < N; i++){
			for(j = 0; j < ver[i].nextnum; j++){
				ver[ver[i].nexts[j].nextver].score = max(ver[i].score + ver[i].nexts[j].c, ver[ver[i].nexts[j].nextver].score);
			}
		}
	}
	long long int ans = ver[N - 1].score;
	for(k = 0; k < N; k++){
		for(i = 0; i < N; i++){
			for(j = 0; j < ver[i].nextnum; j++){
				ver[ver[i].nexts[j].nextver].score = max(ver[i].score + ver[i].nexts[j].c, ver[ver[i].nexts[j].nextver].score);
			}
		}
	}
	if(ans == ver[N - 1].score){
		printf("%lld\n", ans);
	}
	else{
		printf("inf\n");
	}
	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const ll INF = 1e18;
const ld PI = acos((ld) - 1);

int main () {
	string s, t;
	cin >> s >> t;
	int m = (int) t.size();
	int sol = m;
	int n = (int) s.size();
	for (int i = 0; i + (int) t.size() <= n; i++) {
		string cur = s.substr(i, m);
		int com = 0;
		for (int j = 0; j < m; j++) {
			if (cur[j] == t[j]) com++;
		}
		sol = min(sol, m - com);
	}
	
	cout << sol << '\n';
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define pi  3.14159265359
#define mod 1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    ll sum=0;
    for(int i=0;i<s.size();i++)
    {
        sum+=(s[i]-'0');

    }
    if(sum%9==0){
        cout<<"Yes\n";
    }else{
    cout<<"No\n";
    }



}



Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

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

int main(void){
	string S;
	cin>>S;
	
	if(S.substr(0,4)=="YAKI") print("Yes");
	else print("No");
	return 0;
}


Measured memory_bytes: 256
import math
N,K=map(int,input().split())
def c(n,r):
  return math.factorial(n)//(math.factorial(abs(n-r))*math.factorial(r))

for i in range(K):
  if N-K<i:
    print(0)
  else:
    red = c(N-K+1,i+1)
    blue=c(K-1,i)
    ans=(red*blue)%(10**9+7)
    print(ans)

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

int main()
{
    string s, t;
    cin >> s >> t;
    map<char, char> start, goal;
    rep(i, s.length())
    {
        if (start.count(s[i]) || goal.count(t[i]))
        {
            if (start[s[i]] != t[i] || goal[t[i]] != s[i])
            {
                cout << "No" << endl;
                return 0;
            }
        }
        start[s[i]] = t[i];
        goal[t[i]] = s[i];
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 776
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

typedef double db;
struct point {
	db x,y;
	point() {}
	point(db x,db y):x(x),y(y) {}
	void input() { scanf("%lf%lf",&x,&y); }
	void output() { printf("%.10f %.10f\n",x,y); }
	db len() { return sqrt(x*x+y*y); }
	db len2() { return x*x+y*y; }
};
point operator + (const point &a,const point &b) { return point(a.x+b.x,a.y+b.y);}
point operator - (const point &a,const point &b) { return point(a.x-b.x,a.y-b.y);}
point operator * (const point &a,const db &b) { return point(a.x*b,a.y*b);}
point operator / (const point &a,const db &b) { return point(a.x/b,a.y/b);}
db dot(const point &a,const point &b) { return a.x*b.x+a.y*b.y; }
db det(const point &a,const point &b) { return a.x*b.y-a.y*b.x; }
struct line {
	point a,b;
	line() {}
	line(point a,point b):a(a),b(b) {}
};
point proj(const line &a,const point &b) {
	return a.a+(a.b-a.a)*dot(a.b-a.a,b-a.a)/(a.b-a.a).len2();
}
point reflect(const line &a,const point &b) {
	return proj(a,b)*2-b;
}

int q;
int main() {
	point a,b;
	a.input(); b.input();
	line p(a,b);
	scanf("%d",&q);
	rep(i,0,q) {
		a.input();
		reflect(p,a).output();
	}
}

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

int main()
{
	const size_t MAX = 1000000;

	bitset<MAX> primebox;
	primebox.set();
	primebox.reset(0);
	primebox.reset(1);

	for(int i = 2; i < MAX; i++)
	{
		if(!primebox.test(i))
			continue;

		for(int j = i*2; j < MAX; j += i)
			primebox.reset(j);
	}

	size_t n;
	while(cin >> n)
	{
		int found;
		if(n < 2)
			found = 0;
		else if(n == 2)
			found = 1;
		else
		{
			found = 1;
			for(size_t i = 3; i <= n; i += 2)
				if(primebox.test(i))
					found++;
		}

		cout << found << endl;
	}

	return 0;
}

Measured memory_bytes: 1288
import java.util.*;

// ABC 62-D
// http://abc062.contest.atcoder.jp/tasks/arc074_b

public class Main {
	
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		char[] c = in.next().toCharArray();
		int[] occur = new int[26];
		
		boolean isAllDiff = true;
		for (int i = 0; i < c.length && isAllDiff; i++) {
			if (occur[c[i] - 'a'] > 0) {
				isAllDiff = false;
			} else {
				occur[c[i] - 'a']++;
			}
		}
		
		System.out.println(isAllDiff ? "yes" : "no");
	}
}

Measured memory_bytes: 24788
import sys
input = sys.stdin.readline

x, k, d = map(int, input().split())

a = abs(x) // d
b = abs(x) // d + 1

if a > k:
    print(abs(x) - k * d)
else:
    if b < a:
        a = b

    if (k - a) % 2 == 0:
        print(abs(x) - a * d)
    else:
        print(min(abs(abs(x) - a * d + d), abs(abs(x) - a * d - d)))


Measured memory_bytes: 9212
import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
from fractions  import gcd

#input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
a.sort()
res=a.pop()
ans=[]
while a:
    l=a.pop()
    if res==l:
        ans.append(l)
        if a:
            res=a.pop()
        else:
            break
    else:
        res=l
    if len(ans)==2:
        break
if len(ans)<2:
    print(0)
else:
    print(ans[0]*ans[1])

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int N;
int A[100100], B[100100], C[100100];

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

    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> A[i];
    }

    for(int i=0;i<N;++i){
        std::cin >> B[i];
    }

    for(int i=0;i<N;++i){
        std::cin >> C[i];
    }

    sort(A, A+N);
    sort(B, B+N);
    sort(C, C+N);

    ll res = 0ll;
    for(int i=0;i<N;++i){
        if(A[0] >= B[i] || C[N-1] <= B[i]){
            continue;
        }

        int n = lower_bound(A, A + N, B[i]) - A;

        int64_t lb = N - 1, ub = -1;

        while(std::abs(ub - lb) > 1){
            int64_t mid = (lb + ub) / 2;

            if(C[mid] > B[i]){
                lb = mid;
            }else{
                ub = mid;
            }
        }

        int m = N - lb;

        res += 1ll * n * m;
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 1408
n = int(input())
ans = [0] * (n+1)

for y in range(1, n-1):
    for x in range(1, n-1):
        for z in range(1, n-1):
            if x**2 + y**2 + z**2 + x*y + y*z + z*x <= n:
                ans[x**2 + y**2 + z**2 + x*y + y*z + z*x]+=1
            elif x**2 + y**2 + z**2 + x*y + y*z + z*x > n:
                break
for i in range(1, n+1):
    print(ans[i])

Measured memory_bytes: 68872
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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;}

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    map<ll,int> m;
    set<ll> s;
    REP(i,n){
        cin >> a[i];
        m[a[i]]++;
        s.insert(a[i]);
    }
    auto itr=s.begin();
    if(m.size()==1&&a[0]==0){
        cout << "Yes" << endl;
    }
    else if(n%3==0&&m.size()==3){
        ll x=*itr;
        ll a=m[*itr];itr++;
        ll y=*itr;
        ll b=m[*itr];itr++;
        ll z=*itr;
        ll c=m[*itr];
        ll tmp=x^y;
        if(a==b&&b==c&&tmp==z){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else if(n%3==0&&m.size()==2){
        ll x=*itr;
        ll a=m[*itr];itr++;
        ll y=*itr;
        ll b=m[*itr];
        if(x==0){
            if(b==a*2){
                cout << "Yes" << endl;
            }
            else{
                cout << "No" << endl;
            }
        }
        else if(y==0){
            if(a==b*2){
                cout << "Yes" << endl;
            }
            else{
                cout << "No" << endl;
            }
        }
        else{
            cout << "No" << endl;
        }
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 12092
n,m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
sum = 0
tot = a.inject(:+)
a.each do |i|
  sum += 1 if i >= (tot / (4 * m).to_f)
end

if sum >= m
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;

int main(void){
    ll N, T;
    vector< pair<ll, ll> > dish;
    static ll dp[3005][3005];
    ll A, B;
    MEMSET(dp, 0);
    cin>>N>>T;
    rep(i, N){ cin>>A>>B;
        dish.push_back({A, B});
    }
    sort(all(dish));
    rep(i, N){
        rep(j, T){
            if(dish[i].first+j<=T){
        dp[i+1][j+dish[i].first]=max(dp[i][j]+dish[i].second, dp[i+1][j+dish[i].first]);
            } else{
            dp[i+1][T]=max(dp[i][j]+dish[i].second, dp[i+1][T]);
            }
            dp[i+2][T]=dp[i+1][T];
            dp[i+1][j]=max(dp[i+1][j], dp[i][j]);
        }
    }
    ll Maxim=0;
    /*rep(i, T+1){
        cout<<i <<"\t";
        rep(j, N+1){
            cout<<dp[j][i]<<"\t";
        }
        cout<<endl;
    }*/
    rep(i, T+1){
        Maxim=max(dp[N][i], Maxim);
    }
    cout<<Maxim<<endl;
    
    return 0;
}


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

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = (1<<14) * 17 + 30;

int ch[maxn][8];
int fail[maxn][8];
bool val[maxn];

int tt = 1;
int getch(int p, int d){
  if(ch[p][d] == 0){
    tt++;
    ch[p][d] = tt;
  }
  return ch[p][d];
}
ll dp[maxn][40];//we can run sliding window if need be...
ll perform(int v, int n){
  if(n == 0) return 1;
  ll & ans = dp[v][n];
  if(ans != -1) return ans;
  ans = 0;
  for(int d=0;d<8;d++){
    int u = -1;
    if(ch[v][d] != 0) u = ch[v][d];
    else u = fail[v][d];
    assert(u != 0);
    if(val[u]){
      continue;
    }
    if(d == 0){
      ans += 3 * perform(u, n-1);
      ans %= mod;
    }
    else{
      ans += perform(u, n-1);
      ans %= mod;
    }
  }
  return ans;
}

int main(){
  memset(dp, -1, sizeof(dp));
  int n; cin >> n;
  int x,y,z; cin >> x >> y >> z;
  for(int s1 = 0; s1 < (1 << x-1); s1++){
    for(int s2 = 0; s2 < (1<<y-1); s2++){
      for(int s3 = 0; s3 < (1<<z-1); s3++){
	int p = 1;
	int d = 1;
	for(int i=0;i<x-1;i++){
	  if(s1 & (1<<i)){ p = getch(p,d); d = 1;}
	  else d++;
	} p = getch(p, d); d = 1;

	for(int i=0;i<y-1;i++){
	  if(s2 & (1<<i)){ p = getch(p,d); d = 1; }
	  else d++;
	} p = getch(p,d); d = 1;

	for(int i=0;i<z-1;i++){
	  if(s3 & (1<<i)){ p = getch(p,d); d = 1; }
	  else d++;
	} p = getch(p,d); d = 1;

	val[p] = true;
      }
    }
  }

  //fancy!
  deque<int> Q;
  Q.push_back(1);
  for(int d=0;d<8;d++){
    fail[1][d] = 1;
  }
  
  while(!Q.empty()){
    int v = Q.front(); Q.pop_front();
    for(int d=0;d<8;d++){
      if(ch[v][d] == 0) continue;
      int c = ch[v][d];
      Q.push_back(c);
      int u = fail[v][d];
      val[c] = (val[c] | val[u]);
      for(int e=0;e<8;e++){
	if(ch[u][e] != 0) fail[c][e] = ch[u][e];
	else fail[c][e] = fail[u][e];
	assert(fail[c][e] != 0);
      }
    }
  }
  ll xx = perform(1, n);
  ll tot = 1;
  for(int i=0;i<n;i++){
    tot = tot * 10LL;
    tot %= mod;
  }
  ll ans = tot - xx; ans %= mod;
  cout<< (ans+ mod) % mod << "\n";
}


Measured memory_bytes: 89472
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
using pii = std::pair<int, int>;
#define SORT(v) std::sort(v.begin(), v.end())
int main(){
	int N,M,count=0;
    cin >> N;
    if(N==7||N==5||N==3) cout <<"YES"<<endl;
    else cout << "NO" <<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,d=1;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    if(d>k){
      d+=k;
    }else{
      d+=d;
    }
  }
  cout<<d<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n;
int a[200010],h[200010];
int dp[200010];
int bit[200010];
void update(int k,int x){
	for(int i=k+1;i<=200001;i+=i&-i)bit[i]=max(bit[i],x);
}
int query(int k){
	int res=0;
	for(int i=k;i>0;i-=i&-i)res=max(res,bit[i]);
	return res;
}
signed main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>h[i];
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<=200000;i++)dp[i]=-2e18;
	dp[0]=0;
	for(int i=0;i<=200001;i++)bit[i]=-2e18;
	update(0,0);
	for(int i=0;i<n;i++)dp[h[i]]=max(dp[h[i]],query(h[i])+a[i]),update(h[i],dp[h[i]]);
	cout<<query(n+1)<<endl;
	return 0;
}


Measured memory_bytes: 6528
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main{
    public static void main(String[] args) throws IOException{

        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(bf.readLine());
        StringBuilder ans=new StringBuilder();


        for(int i=0;i<n;i++){
            String[] str=bf.readLine().split(" ");

            double x=Math.pow(Integer.parseInt(str[0]),2);
            double y=Math.pow(Integer.parseInt(str[1]),2);
            double z=Math.pow(Integer.parseInt(str[2]),2);


            if(x+y==z || x+z==y || y+z==x)
                ans.append("YES\n");
            else
                ans.append("NO\n");
        }
        System.out.print(ans);
    }
}

Measured memory_bytes: 25680
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<ll, int> mp;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	string a = "";
	for (int i = 0; i < s.size(); i++) {
		if (s.at(i) == '0') {
			a += "0";
		}
		else if (s.at(i) == '1') {
			a += "1";
		}
		else {
			if (a != "") a.erase(a.end() - 1);
		}
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAXN 105
int arr[MAXN];
int n,ans,a,b,c;
//ans=sum(xi^2)+n*p^2-2*sum(x)*p
// p(2*n-2*sum(x)*p)

// p=-()
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++)
    {cin>>arr[i];
     c+=arr[i]*arr[i];
     b+=arr[i];
    }
    b=-2*b;
    a=n;
    double x=(-1.0*b/(2*a));
    int x1=(int)(x+0.5),x2=(int)(x-0.5);
    int ans1=a*x1*x1+b*x1+c;
    int ans2=a*x2*x2+b*x2+c;
    ans=min(ans1,ans2);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
//21171_somesh || asomesh999

#include<bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(long long i=a;i<b;i++)
#define io ios::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
long int mod=1000000007;

int main()
{
	io
	#ifdef CODE
		clock_t startTime = clock();
		freopen("input.txt","r",stdin);
	#endif

	ll x, y, red, green, color;
	cin >> x >> y >> red >> green >> color;
	vl arr(red), brr(green), crr(color);
	multiset<ll> reds, greens;
	multiset<ll, greater<ll>> colors;
	fr(i, 0, red) {
		ll xx;
		cin >> xx;
		reds.insert(xx);
	}
	fr(i, 0, green) {
		ll xx;
		cin >> xx;
		greens.insert(xx);
	}
	fr(i, 0, color) {
		ll xx;
		cin >> xx;
		colors.insert(xx);
	}
	while(reds.size() > x) {
		reds.erase(reds.begin());
	}
	while(greens.size() > y) {
		greens.erase(greens.begin());
	}
	while(!colors.empty()) {
		auto it = reds.lower_bound(*colors.begin());
		auto it1 = greens.lower_bound(*colors.begin());
		if (*it != *reds.begin() && *it1 != *greens.begin()) {
			if (*reds.begin() < *greens.begin()) {
				reds.erase(reds.begin());
				reds.insert(*colors.begin());
				colors.erase(colors.begin());
			} else {
				greens.erase(greens.begin());
				greens.insert(*colors.begin());
				colors.erase(colors.begin());
			}
		} else if (*it != *reds.begin()) {
			reds.erase(reds.begin());
			reds.insert(*colors.begin());
			colors.erase(colors.begin());
		} else if (*it1 != *greens.begin()) {
			greens.erase(greens.begin());
			greens.insert(*colors.begin());
			colors.erase(colors.begin());
		} else {
			break;
		}
	}
	ll sum = 0;
	for (auto it : reds) sum += it;
	for (auto it : greens) sum += it;
	cout << sum;

	#ifdef CODE
		cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;
	#endif
	return 0;
}

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

int main(){
    string s,t;
    int j=0,k=0,N;
    cin >> s;
    N=s.length();
    for(j=0;j<N;j++){
        if(s[j]=='A') break;
    }
    reverse(s.begin(),s.end());
    for(k=0;k<N;k++){
        if(s[k]=='Z') break;
    }

    cout<<N-j-k<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lf long double
#define vi vector<int>
#define vl vector<long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define MOD 1000000007
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define in insert
#define all(x) x.begin(),x.end()
#define zapp ios::sync_with_stdio(false);cin.tie(0)
ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + MOD : res);}
ll power(ll x, ll y) {if (y < 0) return 1; ll res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll inv(ll x){return power(x, MOD - 2);}
const int MAXN = 1e5 + 5;
//const bool is_in = container.find(element) != container.end();
int main()
{
	zapp;
	ll a,b;
	cin>>a>>b;
	cout<<a*b;
}




Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
// auto mod int
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod; return *this;}
  mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod; return *this;}
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
struct Combination {
  vector<mint> fact, ifact;
  Combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  int n,m;
  cin >> n >> m;
  vector<mint> v(m+1);
  v[0]=1;
  rep(i,m) v[i+1]=v[i]*(i+1);

  Combination c(m);
  mint ans;
  rep(i,n+1){
    mint t = c(n,i)*c(m-i,n-i)*v[n-i];
    if(i&1) ans -= t;
    else ans += t;
  }
  ans *= c(m,n)*v[n];
  cout << ans << endl;
}


Measured memory_bytes: 14668
import java.util.*;

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

        for(int n=0; n<sb.length(); n++){
            switch(sb.substring(n, n+1)){
                case "P":
                    break;
                case "D":
                    break;
                case "?":
                    sb.replace(n, n+1, "D");
                    break;
            }
        }

        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 50284
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  int a,b;cin>>a>>b;
  cout<<(a+b-1)/b;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <numeric>

using namespace std;

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

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

const int Maxn = 10010;

int n;
int c1, c2, c3;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    int ans = 0;
    string s;
    for (int i = 0; i < n; ++i) {
        cin >> s;
        int m = (int) s.size();
        for (int j = 1; j < m; ++j) {
            if (s[j - 1] == 'A' && s[j] == 'B') ++ans;
        }
        if (s.front() == 'B' && s.back() == 'A') ++c1;
        else if (s.back() == 'A') ++c2;
        else if (s.front() == 'B')++c3;
    }

    if (c2 == 0 && c3 == 0 && c1 > 0) ans += c1 - 1;
    else ans += c1 + min(c2, c3);

    cout << ans << endl;
}

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

typedef pair<int, int> P;

int base[11];

int enc(int n, const int *c) {
  int r = 0;
  for (int i=0; i<n; i++) {
    r += c[i] * base[i];
  }
  return r;
}

void dec(int n, int p, int *c) {
  int t = p;
  for (int i=0; i<n; i++) {
    c[i] = t % 3; 
    t /= 3;
  }
}

int main() {
  string line;
  int n, c0, rr, gg, bb, c, m, t1, t2, t3;
  int color[10];
  bool used[60000];
  bool found;
  queue<P> q;

  base[0] = 1;
  for (int i=1; i<=10; i++) {
    base[i] = base[i-1]*3;
  }

  while (1) {
    getline(cin, line);
    if (line == "0") break;
    n = line.length();
    for (int i=0; i<n; i++) {
      if (line[i] == 'r') {
        color[i] = 0;
      } else if (line[i] == 'g') {
        color[i] = 1;
      } else {
        color[i] = 2;
      }
    }
    for (int i=0; i<base[n]; i++) {
      used[i] = false;
    }

    while (!q.empty()) q.pop();
    c0 = enc(n, color);
    for (int i=0; i<n; i++) color[i] = 0;
    rr = enc(n, color);
    for (int i=0; i<n; i++) color[i] = 1;
    gg = enc(n, color);
    for (int i=0; i<n; i++) color[i] = 2;
    bb = enc(n, color);
    found = false;
    q.push(make_pair(c0, 0));
    used[c0] = true;
    while (!q.empty()) {
      c = q.front().first;
      m = q.front().second;
      q.pop();
      if (c == rr || c == gg || c == bb) {
        found = true;
        break;
      }
      dec(n, c, color);
      for (int i=0; i<n-1; i++) {
        if (color[i] != color[i+1]) {
          t1 = color[i];
          t2 = color[i+1];
          t3 = 3 - t1 - t2;
          color[i] = color[i+1] = t3;
          c = enc(n, color);
          color[i] = t1;
          color[i+1] = t2;
          if (used[c]) continue;
          q.push(make_pair(c, m+1));
          used[c] = true;
        }
      }
    }
    if (!found) {
      cout << "NA" << endl;
    } else {
      cout << m << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1292