akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[2222][2222];
int A[2222];
int n;
int dfs(int l,int r,int f){
  if((r+1)%n==l) return 0; 
  if(~dp[l][r]) return dp[l][r];
  int res=0;
  int nl=(l-1+n)%n,nr=(r+1)%n;
  if(f){
    if(A[nl]>A[nr]) res=dfs(nl,r,0);
    else res=dfs(l,nr,0);
  }else{
    res=max(res,dfs(nl,r,1)+A[nl]);
    res=max(res,dfs(l,nr,1)+A[nr]);
  }
  return dp[l][r]=res;
}
signed main(){
  cin>>n;
  for(int i=0;i<n;i++) cin>>A[i];
  memset(dp,-1,sizeof(dp));
  int ans=0;
  for(int i=0;i<n;i++) ans=max(ans,dfs(i,i,1)+A[i]);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 41776
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);(i)++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;(i)>=(int)(m);(i)--)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = 998244353;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


//最大公約数
ll gcd(ll m, ll n) {
	if (n == 0)return m;
	return gcd(n, m % n);
}//gcd

 //最小公倍数
ll lcm(ll m, ll n) {
	return m / gcd(m, n) * n;
}


void solve() {

	ll n, k;
	cin >> n >> k;
	Array a(n);
	REP(i, n) cin >> a[i];

	ll d = a[0];//作れる最小の値
	REP(i, n) d = gcd(d, a[i]);
	bool flag = false;
	REP(i, n) {
		if (a[i] == k) {
			flag = true;
			break;
		}
		if (a[i] > k) {
			if ((a[i] - k) % d == 0) {
				flag = true; 
				break;
			}
		}
	}
	if (flag) cout << "POSSIBLE" << en;
	else cout << "IMPOSSIBLE" << en;
}

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

	solve();
	//int t; cin >> t; REP(i, t) solve();

	return 0;
}


Measured memory_bytes: 1024
import java.io.*;
import java.util.*;

public class  Main{
	static long mod=(long)1e9+7;
	public static void main(String[] args) throws Exception{
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();
		long[]power2=new long[n+1];
		power2[0]=1;
		for(int i=1;i<=n;i++)power2[i]=(power2[i-1]*2)%mod;
		Long[]in=sc.takearrlobj(n);
		Arrays.sort(in);
		long ans=0;
		for(int i=0;i<n;i++) {
			int after=n-i-1,before=i;;
			long inc=(power2[before]*power2[before])%mod;
			inc=(inc*power2[after+1])%mod;
			long inc2=power2[after];
			long inc3=after-1<0?0:(after*power2[after-1])%mod;
			long mul=(inc2+inc3)%mod;
			inc=(inc*mul)%mod;
			inc=(inc*in[i])%mod;
			ans=(ans+inc)%mod;
		}
		pw.println(ans);
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] takearr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] takearrl(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public Integer[] takearrobj(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] takearrlobj(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 58680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
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;
    cout << pow(n, 3) << endl;
}

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

int N, M;
long long H[1000000];
int e[1000000] = {0};

int main () {
  cin >> N >> M;
  for(int i = 1; i <= N; i++) {
    cin >> H[i];
  }


  for(int i = 0; i < M; i++) {
    int a = 0, b = 0;
    cin >> a >> b;
    if(H[a] < H[b]) {
      if(e[b] == 0) {
        e[b] = 1;
      } 

      if(e[a] == 0) {
        e[a] = -1;
      }
      if(e[a] == 1) {
        e[a] = 2;
      }
    } else if(H[a] > H[b]) {
      if(e[b] == 0) {
        e[b] = -1;
      }
      if(e[b] == 1) {
        e[b] = 2;
      }
      if(e[a] == 0) {
        e[a] = 1;
      }
    } else {
      if(e[a] == 0) {
        e[a] = -1;
      }
      if(e[b] == 0) {
        e[b] = -1;
      }
      if(e[a] == 1) {
        e[a] = 2;
      }
      if(e[b] == 1) {
        e[b] = 2;
      }
    }
  }

  int count = 0;
  for(int i = 1; i <= N; i++) {
    if(e[i] == 1 || e[i] == 0) {
      count += 1;
    }
  }

  cout << count << endl;

  // cout << e[1] << e[2] << e[3] << e[4] << e[5] << e[6] << endl;

  return 0;
}

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

int main (){
  string S;
  cin>>S;
  if(S=="SUN"){
    cout<<7<<endl;
  }
  else if(S=="MON"){
    cout<<6<<endl;
  }
  else if(S=="TUE"){
    cout<<5<<endl;
  }
  else if(S=="WED"){
    cout<<4<<endl;
  }
  else if(S=="THU"){
    cout<<3<<endl;
  }
  else if(S=="FRI"){
    cout<<2<<endl;
  }
  else{
    cout<<1<<endl;
  }
}

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

int main (){
string S;
  int K;
  int cnt = 0;
  string ans;
  cin >> S >> K;
  for(int i = 0; i < S.size();i++){
  	if(S[i] != '1'){
    	ans = S[i];
      break;
    }else{
    	cnt++;
    }
  }
  if(K <= cnt){
  	ans = '1';
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int	n;
  char	s[100+1]={0};
  char	t[100+1]={0};
  
  scanf("%d", &n);
  scanf("%s %s", s, t);
  for(int i=0; i<n; i++){ printf("%c%c", s[i], t[i]); }
  return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

static int ma = 1000100000;

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

  int N, K, Q;
  cin >> N >> K >> Q;

  vector<int> A(N, 0); // 正解した問題数
  int a;
  rep(i, 0, Q) {
    cin >> a;
    a--;
    A[a]++;
  }

  rep(i, 0, N) {
    int miss = (Q - A[i]);
    if (miss >= K) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }


  return 0;
};


Measured memory_bytes: 1024
#include <stdio.h>

long long func(long long n){
    long long result = 1;
    long long i;

    for(i = 1; i <= n; i++) {
        result*=i;
        result%=1000000007;
    }
    return result;
}

int main(void){
    long long n,m,ans;
    scanf("%lld %lld",&n,&m);
    if(n==m){
        ans=func(n)*func(m)%1000000007;
        ans=ans*2%1000000007;
        printf("%lld\n",ans);
    }else if(((n-m)==1)||((n-m)==-1)){
        ans=func(n)*func(m)%1000000007;
        printf("%lld\n",ans);
    }else{
        printf("0\n");
    }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define RREP(i,n) for(long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define llINF (long long) 9223372036854775807
#define loINF (long) 2147483647
#define shINF (short) 32767
#define SORT(c) sort((c).begin(),(c).end())
#define MIN(vec) *min_element(vec.begin(), vec.end());
#define MAX(vec) *max_element(vec.begin(), vec.end());
#define UNIQ(vec) vec.erase(unique(vec.begin(), vec.end()),vec.end());
#define IN(n,m)  (!(m.find(n) == m.end()))
#define TO_INT(vec,s) REP(i,s.length()){vec.push_back(s[i] - ‘0’);}
#define ENUM_v(vec) for (auto e : vec)
#define dump_MAP(m) for(auto itr = m.begin(); itr != m.end(); ++itr) { cerr << itr->first << " --> "  << itr->second << endl; }
#define FINDL(vec,x) (lower_bound(vec.begin(),vec.end(),x) - vec.begin())
#define FINDU(vec,x) (upper_bound(vec.begin(),vec.end(),x) - vec.begin())

using namespace std;
typedef vector<long> VI;
typedef vector<VI> VVI;
typedef map<long,long long> mp;
using ll = long long int;
constexpr long mod = 1000000007;

long factorial[200000];
long fac_inv[200000];
// a_inverseをmodで割った時の余りを返す。
long inv_mod(long long a){
	long m = mod - 2;
	long long p = a;
	a = 1;
	while (m != 0){
		if (m & 1) {
			a = (a * p) % mod;
		}
		p = (p * p) % mod;
		m >>= 1;
	}	
	return a;
}

long nCr(long n,long r) {
	return ((factorial[n] * inv_mod(factorial[r]))%mod) * inv_mod(factorial[n-r]) % mod;
}
int main(void) {
	long H,W,A,B;
	cin >> H >> W >> A >> B;
	factorial[0] = factorial[1] = 1;
	FOR(i,2,200001) factorial[i] = (factorial[i-1] * i)%mod;

	long N1 = (H-A) + B - 1;
	long R1 = B;
	long N2 = (A) + (W-B) - 2;
	long R2 = (W-B)-1;
	long long ans = 0LL;
	REP(i,R2+1) {
		ans += ((nCr(N1+i,R1+i) * nCr(N2-i,R2-i))%mod);
		//dump(nCr(N1+i,R1+i))
		//dump(nCr(N2-i,R2-i))
	}
	
	cout << ans%mod << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp> // Common file
    #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
    #define int         int64_t
    #define ii          pair<int,int>
    #define dd          pair<double,double>
    #define vi          vector<int>
    #define pb          push_back
    #define all(x)      (x).begin(), (x).end()
    #define checkBit(v, p)      (v&(1LL << p))
    #define loop(i,a,b) for(int i = a;i < int(b);i++)
    #define x           first
    #define y           second
    using namespace std;

    int inf = 4e18, mod = 1e9+7;
    vector<vector<double>> g;

    vector<double> dijkstra(int s){
        int n = g.size();
        vector<double> dis(n, inf);
        set<pair<double, int>> S;
        dis[s] = 0;
        S.insert({0, s});
        while(!S.empty()){
            int u = S.begin()->second;
            S.erase(S.begin());

            for(int i=0;i<g[u].size();i++){
                double w = g[u][i];
                if(dis[i] > dis[u] + w){
                    S.erase({dis[i], i});
                    dis[i] = dis[u] + w;
                    S.insert({dis[i], i});
                }
            }
        }
        return dis;
    }



    double dist(pair<double, double> & a, pair<double, double> & b){
        return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
    }
    int32_t main()
    {
        ios_base::sync_with_stdio(false); cout << fixed <<setprecision(11);
        vector<pair<pair<double,double>,int>> cir;
        cir.resize(2);
        cin >> cir[0].x.x >> cir[0].x.y >> cir[1].x.x >> cir[1].x.y;
        cir[0].y = cir[1].y = 0;
        int n; cin >> n;
        g.resize(n+2, vector<double>(n+2));
        cir.resize(n+2);
        for(int i=0;i<n+2;i++){
            if(i > 1)cin >> cir[i].x.x >> cir[i].x.y >> cir[i].y;
            g[i][i] = 0;
            for(int j=0;j<i;j++){
                g[i][j] = g[j][i] = max(0.0, dist(cir[i].x, cir[j].x) - cir[i].y - cir[j].y);
            }
        }
        cout << dijkstra(0)[1] << endl;
        return 0;
    }


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

int main(){
 	string n;
  	cin >> n;
  	for(int i = 0 ; i < n.length() ; i ++){
     	if(n[i] == '1') n[i] = '9'; else n[i] = '1'; 
    }
  	cout << n << endl;
}

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

int main(){
  ll n;
  cin >> n;
  if(n==1){
    cout << 1 << endl;
    return 0;
  }
  ll i,j;
  vector<ll> p(100,1);
  
  ll m=n*2;
  i=2;
  j=0;
  while(m>=i*i){
    if(m%i==0){
      p.at(j)=i;
      m=m/i;
      j++;
    }else{
      i++;
    }
  }
  p.at(j)=m;
  
  vector<ll> q(20,1);
  ll s=0;
  for(i=0;i<=j;i++){
    if(i==0||p.at(i)==p.at(i-1)){
      q.at(s) *= p.at(i);
    }else{
      s++;
      q.at(s) *= p.at(i);
    }
  }
  
  s++;
  ll mink=2*n-1,h,a,b,k;
  for(i=0;i<(1<<s);i++){
    bitset<50> bi(i);
    a=1;
    b=1;
    for(h=0;h<s;h++){
      if(bi.test(h)){
        a *= q.at(h);
      }else{
        b *= q.at(h);
      }
    }
    if(a>b){
      k=a;
      while(k<mink&&(k+1)%b!=0){
        k += a;
      }
      if(k<mink){
        mink=k;
      }
    }else{
      k=b-1;
      while(k<mink&&k%a!=0){
        k += b;
      }
      if(k<mink){
        mink=k;
      }
    }
  }
  
  cout << mink << endl;
}

Measured memory_bytes: 3640
#include<stdio.h>
int main(void) {
  int n;
  scanf("%d", &n);
  int a[2][n];
  int i, j;
  for (i = 0; i < 2; i++)
    for (j = 0; j < n; j++)
      scanf("%d", &a[i][j]);
  int ans = a[0][0];
  int k;
  for (k = 0; k < n; k++) {
    ans += a[1][k];
  }
  for (k = 1; k < n; k++) {
    int t = 0;
    int l;
    for (l = 0; l < k; l++)
      t += a[0][l];
    for (l = k - 1; l < n; l++)
      t += a[1][l];
    if (t > ans)
      ans = t;
  }
  printf("%d", ans);
  return 0;
}

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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    int sum = 0;
    int Corrent = 1;
    while(N >= Corrent){
        if(Corrent <= K) sum += X;
        else sum += Y;
        Corrent++;
    }
    cout << sum << endl;
}

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

int main() {
  string s,t; cin>>s>>t;
  reverse(t.begin(), t.end());
  if (s==t) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>	
#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;
#define rep(x, n) for (int x = 1; x <= n; ++x)
#define zrp(x, n) for (int x = n; x > 0; --x)
#define FOR(x, l, r) for (int x = l; x <= r; ++x)
#define foreach(i, x) for (int i = start[x]; i; i = e[i].l)
const int maxN = 100005;
int x[maxN], y[maxN], sa[maxN];

bool cmp(int a, int b)
{
	return x[a] < x[b];
}

int main()
{
	long long n, k;
	cin >> n >> k;
	rep(i, n)
		scanf("%d%d", x + i, y + i);
	rep(i, n) sa[i] = i;
	sort(sa + 1, sa + 1 + n, cmp);
	rep(i, n)
	{
		int j = sa[i];
		if (k <= y[j])
		{
			printf("%d\n", x[j]);
			return 0;
		}
		k -= y[j];
	}
	return 0;
}


Measured memory_bytes: 1408
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * 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;
        MyScanner in = new MyScanner(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, MyScanner in, PrintWriter out) {
            int N = in.Int();
            int[] a = in.Int(N);
            int x = 0;
            int y = 0;
            Arrays.sort(a);
            for (int i = 0; i < N; i++) {
                int v = a[N - 1 - i];
                if (i % 2 == 0) {
                    x += v;
                } else {
                    y += v;
                }
            }
            out.println(x - y);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

        public int[] Int(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Int();
            }
            return a;
        }

    }
}



Measured memory_bytes: 21588
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial
from heapq import heappop, heappush, heappushpop,heapify
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    def rev(n):
        return -n
    N = I()
    A = LI()
    left_sum = [sum(A[:N])]  #left_sum[k]:=N+k個取って、小さいN個を選んだときの合計値
    left = A[:N]
    heapify(left)
    right_sum = [sum(A[2 * N:])]
    right=list(map(rev,A[2*N:]))
    heapify(right)
    for k in range(1, N + 1):
        heappush(left, A[N - 1 + k])
        poped = heappop(left)
        left_sum.append(left_sum[-1] + A[N - 1 + k] - poped)

        heappush(right, -A[-N - k])
        poped = -heappop(right)
        right_sum.append(right_sum[-1] + A[-N - k] - poped)
    ans = -inf
    for k in range(N + 1):
        ans = max(ans, left_sum[k] - right_sum[-k - 1])
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 127036
<>;$x=$==1,s/( \d+)\1*\b/$x*=$&**($a=$&=~y! !!%3);$=*=$&**(-$a%3)/ge,++$h{$x},$t{$x}=$=for`factor`;$\+=$_<2?!!$h{1}:$h{$h{$_}>$h{$t{$_}}?$_:$t{$_}},$h{$_}=$h{$t{$_}}=0for keys%h;print

Measured memory_bytes: 54352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;


int main(){
  ll N;
  cin >> N;
  ll a[N];
  REP(i, 0, N) {
    cin >> a[i];
  }

  // algo

  // count rengas
  ll ans = 0;
  ll current = 1;
  REP(i, 0, N) {
    if (a[i] == current) {
      current++;
    }
    else{
      ans++;
    }
  }

  // cout << "current: " << current << ", ans: " << ans << endl;

  // do not count last rengas
  // for(ll i=N-1; i>=0; i--) {
  //   if(a[i] != (current-1)) {
  //     ans--;
  //   }
  //   else {
  //     break;
  //   }
  // }

  // no way
  if (current == 1) {
    ans = -1;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <locale>

static bool readLines(std::string &str)
{
	std::string tmp;

	if (0x00 == &str) {
		return false;
	}

	while (std::getline(std::cin, tmp)) {
		if (0 < tmp.size()) {
			transform(tmp.begin(), tmp.end(), tmp.begin(), tolower);
			str += tmp;
		}
	}

	return true;
}

static bool countAlpha(const std::string &str, std::vector<int> &v)
{
	if (0x00 == &str || 0x00 == &v) {
		return false;
	}

	if (0 >= v.size()) {
		v.resize(26);
		for (unsigned int i = 0; i < v.size(); i++) {
			v.at(i) = 0;
		}
	}

	char ch;
	int index = 0;
	for (unsigned int i = 0; i < str.size(); i++) {
		ch = str.at(i);
		if (false == std::isalpha(ch))
			continue;
		index = static_cast<int>(ch - 'a');
		v.at(index)++;
	}

	return true;
}

int main()
{
	std::string alpha("abcdefghijklmnopqrstuvwxyz");
	std::string str;
	std::vector<int> vec(26);

	for (unsigned int i = 0; i < vec.size(); i++) {
		vec.at(i) = 0;
	}

	if (true == readLines(str)) {
		countAlpha(str, vec);
		for (unsigned int i = 0; i < vec.size(); i++) {
			std::cout << alpha.at(i) << " : " << vec.at(i) << std::endl;
		}
	}

	return (0);
}

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

int main() {
    string S;
    cin >> S;
    map<char,int> m;
    m['0']=0, m['1']=0;

    rep(i,S.size())
        ++m.at(S.at(i));

    cout << min(m.at('0'),m.at('1'))*2 << endl;
}

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

using namespace std;

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;

long long solve(long long a, long long b) { // a >= b
    long long r = a%b;
    long long d = a/b;
    //d--;
    if(r){ return 2*d*b + solve(b,r); }
    d--;
    return 2*d*b + b;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long n, x;
    cin>>n>>x;
    long long a = max(x, n-x);
    long long b = min(x, n-x);
    cout<<solve(a,b)+n<<endl;
    return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
field = [list(input()) for _ in range(h)]

# for f in field:
#     print(*f)
# print()

cntx = [[0] * w for _ in range(h)]
cnty = [[0] * w for _ in range(h)]

for y in range(h):
    c = 0
    left = 0
    for x in range(w + 1):
        if x < w and field[y][x] == ".":
            c += 1
        else:
            for pos in range(left, x):
                cntx[y][pos] = c
            c = 0
            left = x + 1
for x in range(w):
    c = 0
    left = 0
    for y in range(h + 1):
        if y < h and field[y][x] == ".":
            c += 1
        else:
            for pos in range(left, y):
                cnty[pos][x] = c
            c = 0
            left = y + 1
# for c in cntx:
#     print(*c)
# print()
# for c in cnty:
#     print(*c)

maxv = 0
for y in range(h):
    for x in range(w):
        maxv = max(maxv, cntx[y][x] + cnty[y][x] - 1)
print(maxv)


Measured memory_bytes: 249096
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]

A, B = zip(*AB)
a = list(A)
b = list(B)
a.sort()
b.sort()

if N % 2:
    lb = a[(N - 1) // 2]
    ub = b[(N - 1) // 2]
    ans = ub - lb + 1
else:
    lb = (a[(N - 2) // 2] + a[N // 2]) / 2
    ub = (b[(N - 2) // 2] + b[N // 2]) / 2
    ans = int((ub - lb) * 2) + 1

print(ans)

Measured memory_bytes: 123536
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n'
#define no cout<<"No"<<'\n'
using namespace std;

int main()
{
    godspeed
    ll  i,j,k,l,ans=0,len;
    string s;
    cin>>s;
    for(i=0; s[i]; i++)
    {
        len=0;
        while(s[i]=='A'||s[i]=='C'||s[i]=='T'||s[i]=='G')
        {
            i++;
            len++;
        }
        ans=max(len,ans);
    }
    cout<<ans<<endl;



    return 0;
}





Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
int a[200];
int main()
{
	ll i,j,n,m,sum,x,ans;
	scanf("%lld%lld",&n,&m);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	sum=0;
	for (i=1;i<=n;i++) sum+=a[i];
	x=sum/4/m;
	if (sum%(4*m)>0) x++;
	ans=0;
	for (i=1;i<=n;i++) if (!(a[i]<x)) ans++;
	if (ans>=m) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
import Control.Monad (replicateM,foldM)
import Control.Monad.ST (ST,runST)
import Data.List (sortBy)
import Data.Array (Array,array,listArray,(!),assocs)
import qualified Data.Array.ST as STArr

main = do
    [n,m,h,k] <- getLine >>= return . map read . words
    if all (==0) [n,m,h,k] then return 0 else do
        ps <- replicateM n readLn >>= return . listArray (1,n)
        ls <- replicateM m (getLine >>= return . line)
        print $ solve n ps ls k
        main
    where
    line = (\[a,b] -> (a,b)) . map read . words

solve :: Int -> Array Int Int -> [(Int,Int)] -> Int -> Int
solve n ps ls k =
    goals `seq` swaps `seq`
    (sum $ map pointOf [1..k]) + (minimum (0:(map (uncurry diff) swaps)))
    where
    ls' = sortBy (\x y -> compare (snd x) (snd y)) ls

    (goals,swaps) = runST $ do
        reach <- STArr.newListArray (1,n) [1..n]
            :: ST s (STArr.STArray s Int Int)
        (reach, swaps) <- foldM update (reach,[]) ls'
        reach <- STArr.freeze reach
        let goals = array (1,n) (map (\(a,b)->(b,a)) $ assocs reach)
        return (goals,swaps)

    update (goals,swaps) (a,_) = do
        s1 <- STArr.readArray goals a
        s2 <- STArr.readArray goals (a+1)
        STArr.writeArray goals a s2
        STArr.writeArray goals (a+1) s1
        return (goals, (s1,s2):swaps)

    diff x y
        | (min x y) <= k && (max x y) > k
            = (pointOf (max x y)) - (pointOf (min x y))
        | otherwise
            = 0

    pointOf start = ps ! (goals ! start)

Measured memory_bytes: 76804
let n = read_int ();;

let to_ints (lst : string list):int list = 
 (List.map (fun x -> (int_of_string x)) lst);;

let rec print_list list_ints =
  match list_ints with
    [] -> print_newline ()
  | [n] -> print_int n; print_newline ()
  |[t;h] -> print_int t; print_string " "; print_int h; print_newline ()
  | h::t::t' -> print_int h; print_string " "; print_list (t::t');;

let rec ins n list =
  match list with
    [] -> [n]
  | h::t -> if n <= h then n::h::t
    else h::(ins n t);;
 
let rec aux acc llist list =
  match list with
    [] ->  llist
  | h::t ->
     let i = (ins h acc) in
     aux i ((i @ t) :: llist) t;;

let insort list =
  List.map (fun x -> print_list x) 
    (List.rev (aux [] [] list));;


let lst = (to_ints (Str.split (Str.regexp " ") (read_line ()))) in
insort lst;;

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

int sumDigit(int n){
    // cout << "Called" << endl;
    int ans = 0;
    // cout << "n:" << n << endl;
    while(n){
        ans += n % 10;
        n /= 10;
    }
    // cout << "ans:" << ans << endl;
    return ans;
}

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

    int ans = 0;
    for (int tsumugi = 1; tsumugi <= n; tsumugi++){
        int temp = sumDigit(tsumugi);
        if (temp >= a and temp <=b){
            // cout << "Yes" << endl;
            ans += tsumugi;
            // cout <<"SumAns:" << ans << endl;
        }
    }

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

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

using namespace std;

int gcd(int a, int b){
    if (a < b){
        int c = a;
        a = b;
        b = c;
    }

    int ans = b;
    while(a % ans != 0){
        int c = a % ans;
        a = ans;
        ans = c;
    }

    return ans;
}

int main(){

    int N, K;
    cin >> N >> K;

    vector <int> A(N);
    int Amax = 0;
    for (int i = 0; i < N; i++){
        cin >> A[i];

        if (A[i] > Amax){
            Amax = A[i];
        }
    }
    
    int G = A[0];
    for (int i = 1; i < N; i++){
        G = gcd(G, A[i]);
    }

    if (K % G == 0 && K <= Amax){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void) {
    int N,i;
    long A = 1;
    scanf("%d", &N);
    for (int i = 1; i <= N; i++){
        A *= i;
      A=A%1000000007;
    }
  printf("%d",A);
    return 0;
}

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

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

    if(S=="RRR") cout<<3<<endl;
    else if(S=="SSS") cout<<0<<endl;
    else if(S=="RRS" || S=="SRR") cout<<2<<endl;
    else cout<<1<<endl;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
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(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k,n;cin>>k>>n;
    const int NM = 200010;
    int a[NM];
    rep(i,n){
        cin>>a[i];
    }
    sort(a,a+n);
    int b[NM];
    rep(i, n-1){
        b[i]=a[i+1]-a[i];
    }
    b[n-1]=(k-a[n-1])+a[0];
    sort(b,b+n);
    cout<<k-b[n-1]<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int M, Nmin, Nmax, P[200];

int main(){
    while(1){
        cin >> M >> Nmin >> Nmax;
        if (M == 0 && Nmin == 0 && Nmax == 0)
            break;

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

        int idx = Nmin;
        for (int i = Nmin; i <= Nmax; ++i) {
            if (P[i-1]-P[i] >= P[idx-1] - P[idx]) {
                idx = i;
            }
        }

        cout << idx << endl;
    }
    return 0;
}



Measured memory_bytes: 3052
#include <iostream>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i = k; i < (int)(n); i++)
using namespace std;
int main(){
        int N;
        cin >> N;
        long long ans = 1;
        int n = pow(10,9)+7;
        rep(i,N){
                ans = ans*(i+1)%n;
        }
        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 256
#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


using namespace std;

template<class T>
using vec = std::vector<T>;


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


// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


// Section with adoption of array and vector algorithms.


//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}

template<class T>
vector<T> next_vec(istream& in, size_t n) {
  vector<T> ret(n);
  for (size_t i = 0; i < n; ++i) {
    ret[i] = next<T>(in);
  }
  return ret;
}


void solve(istream& in, ostream& out) {
  auto n = next<int>(in);
  auto k = next<int>(in);
  auto h = next_vec<int>(in, n);
  vec<int64_t> f(n, numeric_limits<int64_t>::max() / 2);
  f[0] = 0;
  FORA(i, 1, n) {
    FOR(j, k) {
      if (i - j - 1 >= 0) {
        f[i] = min(f[i], f[i - j - 1] + abs(h[i] - h[i - j - 1]));
      }
    }
  }
  out << f[n-1] << "\n";
}

//#include <fstream>


int main() {
//  ifstream fin("bridges.in");
//  ofstream fout("bridges.out");
    solve(cin, cout);
//  solve(fin, fout);
    return 0;
}



Measured memory_bytes: 1408
import java.util.Scanner;
import java.util.InputMismatchException;

class Main {
   public static void main(String args[]) {
      int x=0 ,y=0;
      int sum = 0;
      try {
         Scanner scanner = new Scanner(System.in);
         x = scanner.nextInt();
         y = scanner.nextInt();
         scanner.close();
      } catch (InputMismatchException e) {
         System.out.println("error");
      }
      for (int i = 0; i < 2;  i++) {
         if (x<y) {
            sum = sum + y;
            y = y-1;
         }else {
            sum = sum + x;
            x = x-1;
         }
      }
      System.out.println(sum);
   }
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
# define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[10010][100][2];
inline int add(int x, int y, int mod) {
   if (y >= mod) y %= mod;
   if (x >= mod) x %= mod;
   x  += y;
   return (x >= mod ? x - mod : x);
} 
inline int mul(int x, int y, int mod) {
  if (x >= mod) x %= mod;
  if (y >= mod) y %= mod;
  return (x*y) % mod;
}
inline int sub(int x, int y, int mod) {
  x -= y;
  if (x + mod <= 0) {
	x %= mod;
  }
  return (x < 0 ? x+mod : x);
}
vector<int>v;
int k;
int solve(int pos ,int curMod , int f , int n){
	if(pos==n){
		return curMod==0;
	}
	if(dp[pos][curMod][f]!=-1)return dp[pos][curMod][f];
	int lim = (f==0 ? v[pos] : 9);
	int ans =0 ;
	for(int i =0 ;i<=lim;i++){
		int nf=f;
		int newMod =0;
		newMod+=(curMod+i%k)%k;
		if(i < lim && !f)nf =1;
		ans =add(ans, solve(pos+1,newMod,nf,n),MOD);
	}
	return dp[pos][curMod][f]=ans;
}
int go(string &s){
	v.clear();
	memset(dp,-1,sizeof(dp));
	int n = s.size();
	for(auto i : s){
		v.pb(i-'0');
	}
	int ans = solve(0,0,0,n);
	ans = sub(ans,1,MOD);
	return ans;
}
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		string s;
		cin >> s>> k;
		cout << go(s);
	
	}
	cerr << "Time Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}

Measured memory_bytes: 17536
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

bool f(ll v, const VI& vs) {
	ll N = vs.size();
	VI pat = {v/100, v/10%10, v%10};
	ll pi = 0;
	REP(i, N) {
		if(vs[i]==pat[pi]) {
			pi++;
			if(pi==3) return true;
		}
	}
	return false;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	string s;
	while(cin>>N>>s) {
		VI vs(N);
		REP(i, N) vs[i] = s[i]-'0';
		ll ans = 0;
		REP(i, 1000) ans += f(i, vs);
		cout<<ans<<endl;
	}
	
	return 0;
}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << a*b/2 << endl;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, s[105], sum=0;
    cin >> n;
    REP(i,n){
        cin >> s[i];
        sum += s[i];
    }
    sort(s,s+n);
    if(sum%10==0){
        REP(i,n){
            if(s[i]%10>0){
                sum-=s[i];
                break;
            }
        }
    }
    cout << (sum%10==0?0:sum) << endl;
    return 0;
}


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

using namespace std;

struct pole{
    int next;
    int val;
    int vis;
};

pole tab[5007];

int main()
{
    long long int n, i, k, m=0, w=-1000000007, poi, c, kp, l, x;
    cin >> n >> k;
    for(i=0; i<n; i++){
        cin >> tab[i].next;
        tab[i].next--;
    }
    for(i=0; i<n; i++){
        cin >> tab[i].val;
    }
    for(i=0; i<n; i++){
        poi=i;
        c=0;
        m=-1000000007;
        kp=k;
        l=1;
        while((tab[poi].next!=i)&&(kp>0)){
            c+=tab[tab[poi].next].val;
            poi=tab[poi].next;
            m=max(m, c);
            l++;
            kp--;
            //cout << kp << '\n';
        }
        if(kp==0){
            w=max(m, w);
            continue;
        }
        kp+=l-1;
        c+=tab[tab[poi].next].val;
        //cout << c << ' ' << k << '\n';
        m=max(m, c);
        c*=(kp/l-1);
        //cout << c << '\n';
        kp%=l;
        kp+=l;
        poi=i;
        while(kp>0){
            kp--;
            c+=tab[tab[poi].next].val;
            poi=tab[poi].next;
            m=max(m, c);
        }
        w=max(m, w);
    }
    cout << w << '\n';
    return 0;
}


Measured memory_bytes: 3544
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

#define SORT(c) sort((c).begin(),(c).end())
#define DSORT(c, type) sort(ALL(c), greater<type>())

#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SUM(v) accumulate(ALL(v), 0)
#define AVE(v) SUM(v) / (v).size()
// 入力eと同じ値の要素の数
#define COUNT(v, e) count(ALL(v), e)

using namespace std;


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

  int n, k;
  string s;
  cin >> n >> k;
  cin >> s;

  if(s[k-1] == 'A')
    s[k-1] = 'a';
  else if(s[k-1] == 'B')
    s[k-1] = 'b';
  else
    s[k-1] = 'c';

  cout << s << endl;

  return 0;
}

Measured memory_bytes: 256
n, y = map(int, input().split())
y = y/1000
answer= []

for ten in range(n + 1):
    for five in range(n + 1 - ten):
        one = n - ten - five
        if ten * 10 + five * 5 + one == y:
            answer = [ten, five, one]
            break

print(answer[0], answer[1], answer[2]) if answer != [] else print("-1 -1 -1")

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

#define ll long long
#define ld long double
#define pi 3.14159265359

int main(){
    int N, M; cin >> N >> M;
    vector<vector<int>> sc(M,vector<int>(2));
    int ans = 0;
    if(M != 0) {
        for(int i = 0; i < M; i++) {
            for(int j = 0; j < 2; j++) {
                cin >> sc.at(i).at(j);
            }
        }
        sort(sc.begin(), sc.end());
        sc.erase(unique(sc.begin(), sc.end()), sc.end());
        bool judge = true;
        for(int i = 0; i < sc.size(); i++) {
            if(sc.at(i).at(0) == 1 && sc.at(i).at(1) == 0 && N > 1) {
                ans = -1;
                break;
            }
            if(sc.at(i).at(0) == 1) {
                judge = false;
            }
            if(i != sc.size() - 1) {
                if(sc.at(i).at(0) == sc.at(i + 1).at(0) && sc.at(i).at(1) != sc.at(i + 1).at(1)) {
                    ans = -1;
                    break;
                }
            }
            ans += sc.at(i).at(1) * pow(10, N - sc.at(i).at(0));
            if(i == sc.size() - 1) {
                if(judge == true) {
                    ans += pow(10, N - 1);
                }
            }
        }
    }
    else {
        if(N != 1) {
            ans = pow(10, N - 1);
        }
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(int i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl

int main()
{
	ll x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	vector<P> vl;
	FOR(i,0,a)
	{
		ll m;
		cin>>m;
		vl.pb(P(m,2));
	}
	FOR(i,0,b)
	{
		ll m;
		cin>>m;
		vl.pb(P(m,1));
	}
	FOR(i,0,c)
	{
		ll m;
		cin>>m;
		vl.pb(P(m,0));
	}
	sort(all(vl));
	reverse(all(vl));
	ll num = x+y;
	ll ans = 0;
	ll cnt = 0;
	for(int i=0;(i<a+b+c&&cnt<num);i++)
	{
		if(vl[i].se == 2&&x)
		{
			ans+=vl[i].fi;x--;cnt++;
		}
		else if(vl[i].se == 1&&y)
		{
			ans+=vl[i].fi;y--;cnt++;
		}
		else if(vl[i].se == 0)
		{
			ans+=vl[i].fi;cnt++;
		}
	}
	cout<<ans<<endl;
	return 0;
} 


Measured memory_bytes: 11660