akhauriyash/Code-Regression huggingface dataset:
import std.stdio;

void main() {
	int n, q;
	scanf("%d %d\n", &n, &q);
	auto c1 = 'X';
	int cnt = 0;
	int[] cache = [];
	auto s = readln;
	foreach (c; s) {
		if (c1 == 'A' && c == 'C') {
			++cnt;
		}
		c1 = c;
		cache ~= cnt;
	}
	foreach(_;0..q) {
		int l, r;
		scanf("%d %d", &l, &r);
		writeln(cache[r-1] - cache[l-1]);
	}
}


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

using namespace std;

#define N 10000000
__int128 f[N + 1];

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

    int i, j;
    for(i = 1; i <= N; i++) {
        for(j = i; j <= N; j += i) {
            f[j]++;
        }
    }

    __int128 x = 0;
    for(i = 1; i <= n; i++) {
        x += (__int128)i * f[i];
    }
    cout << (unsigned long long)x << endl;

    return 0;
}

Measured memory_bytes: 159880
#include <iostream>
#include <string>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
ll n,x;
cin >>n>>x;
ll m[n];
ll sum=0;
for(ll i=0;i<n;i++){
cin >>m[i];
sum +=m[i];
}
sort(m,m+n);
ll count=x-sum;
count =count/m[0];
cout <<n+count;
return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
constexpr long long MOD = 1000000007;
template<typename T>
struct Choose {
	std::vector<T> fact, inv, invFact;
 
	Choose(T N) :fact(N), inv(N), invFact(N) {
		inv[1] = 1;
        for(int i=2;i<inv.size();++i) inv[i] = MOD - (MOD / i) * inv[MOD % i] % MOD;
		fact[0] = invFact[0] = 1;
        for(int i=1;i<fact.size();++i){
			fact[i] = fact[i - 1] * i % MOD;
			invFact[i] = (invFact[i - 1] * inv[i]) % MOD;
		}
	}
 
	//Get nCk
	T operator () (T n, T k) const {
		if (not ((T)0 <= k and k <= n)) return 0;
		return (((fact[n] * invFact[k]) % MOD) * invFact[n - k]) % MOD;
	}
};
 
 
long long C(Choose<long long> const& choose, long long x, long long y) {
    // O(1)
    return choose(x, y);
}
int main() {
    long long S;
    std::cin >> S;
    Choose<long long> choose(S+1);
    long long ans = 0;
    for (int i=0; i*3 <= S; i++) {
        long long left = S - i * 3;
        ans += C(choose, left + i - 1, i - 1);
        ans = ans % MOD;
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 3624
A, B, C, X, Y = [int(x) for x in input().split(" ")]

min = max(A,B,C)*max(X,Y)*2

for k in range(0,max(X,Y)*2+1,2):
  if A*max(0,X-k/2)+B*max(0,Y-k/2)+C*k < min:
    min = A*max(0,X-k/2)+B*max(0,Y-k/2)+C*k
        
print(int(min))

Measured memory_bytes: 3064
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
const double PI = acos(-1.0);
const string ALP = "abcdefghijklmnopqrstuvwxyz";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
int main(){
  int a,b,c,d;
  cin >> a >> b >> c;
  d = a %= b;
  for(;;){
    if(a==c){
      puts("YES");
      break;
    } else {
      a=(a+d)%b;
    }
    if(d==a){
      puts("NO");
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
struct po{int lx,ly,rx,ry;};
int w,h;
string mp[2][51];
bool visited[51][51][51][51];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};

bool bfs(int lx,int ly,int rx,int ry){
  queue <po> Q;
  Q.push((po){lx,ly,rx,ry});
  while(!Q.empty()){
    po t=Q.front();Q.pop();
    int cnt=(mp[0][t.ly][t.lx]=='%')+(mp[1][t.ry][t.rx]=='%');
    if(cnt==2)return true;
    if(visited[t.lx][t.ly][t.rx][t.ry]||cnt==1)continue;
    visited[t.lx][t.ly][t.rx][t.ry]=1;
    for(int i=0;i<4;i++){
      int flg=0;
      int nlx=t.lx+dx[i],nly=t.ly+dy[i];
      int nrx=t.rx-dx[i],nry=t.ry+dy[i];
      if(nlx<0||nly<0||nlx>=w||nly>=h||mp[0][nly][nlx]=='#')nlx=t.lx,nly=t.ly,flg++;
      if(nrx<0||nry<0||nrx>=w||nry>=h||mp[1][nry][nrx]=='#')nrx=t.rx,nry=t.ry,flg++;
      if(flg==2)continue;
      Q.push((po){nlx,nly,nrx,nry});
    }
  }
  return false;
}

int main(){
  while(1){
    cin >>w>>h;
    if(!w&&!h)break;
    for(int i=0;i<h;i++)cin>>mp[0][i]>>mp[1][i];
    int lx,ly,rx,ry;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	if(mp[0][i][j]=='L')lx=j,ly=i;
	if(mp[1][i][j]=='R')rx=j,ry=i;
      }

    memset(visited,0,sizeof(visited));
    if(bfs(lx,ly,rx,ry))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 11332
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
int N_MAX=50;
long double INF=1000000.0;
int main()
{
  int n,i,j,k,l;
  bool f;
  long double a,b,r,rr,res=INF,t;
  long double x[N_MAX],y[N_MAX],c[4],d[2];
  cin >> n;
  for(i=0;i<n;i++)
    cin >> x[i] >> y[i];
  for(i=0;i<=n-2;i++)
    for(j=i+1;j<=n-1;j++){
      a=(x[i]+x[j])/2;
      b=(y[i]+y[j])/2;
      r=(x[i]-a)*(x[i]-a)+(y[i]-b)*(y[i]-b);
      f=1;
      for(l=0;l<n;l++){
        rr=(x[l]-a)*(x[l]-a)+(y[l]-b)*(y[l]-b);
        if(rr>r){ f=0; break; }
      }
      if(f==1) res=min(res,r);
    }
  for(i=0;i<=n-3;i++)
    for(j=i+1;j<=n-2;j++){
      c[0]=x[i]-x[j];
      c[1]=y[i]-y[j];
      d[0]=c[0]*(x[i]+x[j])+c[1]*(y[i]+y[j]);
      for(k=j+1;k<=n-1;k++){
        c[2]=x[j]-x[k];
        c[3]=y[j]-y[k];
        d[1]=c[2]*(x[j]+x[k])+c[3]*(y[j]+y[k]);
        t=c[0]*c[3]-c[1]*c[2];
        if(t==0) continue;
        a=c[3]*d[0]-c[1]*d[1];
        b=-c[2]*d[0]+c[0]*d[1];
        r=(2*t*x[i]-a)*(2*t*x[i]-a)+(2*t*y[i]-b)*(2*t*y[i]-b);
        f=1;
        for(l=0;l<n;l++){
          rr=(2*t*x[l]-a)*(2*t*x[l]-a)+(2*t*y[l]-b)*(2*t*y[l]-b);
          if(rr>r){ f=0; break; }
        }
        if(f==1) res=min(res,r/(4*t*t));
      }
    }
  res=sqrt(res);
  cout << setprecision(20) << res << endl;
  return 0;
}

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

ll dp[101][100002],arr[101]={0};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        for(int j=0;j<=k;j++)
            dp[i][j]=0;
    }
    if(!k){
        cout<<1<<endl;
        return 0;
    }
    for(int i=0;i<n;i++)
        dp[i][0]=1;
    for(int i=1;i<=k;i++){
        if(i<=arr[0])
            dp[0][i]+=1;
        dp[0][i] = (dp[0][i-1]+dp[0][i])%mod;
    }
    for(int i=1;i<n;i++){
        for(int j=1;j<=k;j++){
            ll t = max(ll(0),j-arr[i]);
            dp[i][j] = (dp[i][j]+dp[i-1][j]+dp[i][j-1])%mod;
            if(t)
                dp[i][j] = (dp[i][j]-dp[i-1][t-1]+mod)%mod;
        }
    }
    /*for(int i=0;i<n;i++){
        for(int j=0;j<=k;j++)
            cout<<dp[i][j]<<" ";
        cout<<endl;
    }*/
    ll ans = dp[n-1][k];
    if(k)
        ans =(ans-dp[n-1][k-1]+mod)%mod;
    cout<<ans<<endl;
}


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

const int INF = 1e9 + 1;

int cnt = 0;

void merge( int* a, int left, int mid, int right ){
  int n1 = mid - left;
  int n2 = right - mid;
  int* L = new int[n1 + 1];
  int* R = new int[n2 + 1];
  for( int i = 0; i < n1; i++ ) L[i] = a[left + i];
  for( int i = 0; i < n2; i++ ) R[i] = a[mid + i];
  L[n1] = INF;
  R[n2] = INF;

  int i = 0, j = 0;
  for( int k = left; k < right; k++ ){
    if( L[i] <= R[j] ){
      a[k] = L[i++];
    }else{
      a[k] = R[j++];
    }
    cnt++;
  }
}

void mergeSort( int* a, int left, int right ){
  if( right - left > 1 ){
    int mid = ( right + left ) / 2;
    mergeSort( a, left, mid );
    mergeSort( a, mid, right );
    merge( a, left, mid, right );
  }
}

int main(){
  int n; cin >> n;
  int* s = new int[n];
  for( int i = 0; i < n; i++ ) cin >> s[i];

  mergeSort( s, 0, n );

  for( int i = 0; i < n; i++ ){
    cout << s[i];
    if( i == n - 1 ) cout << endl;
    else cout << " ";
  }

  cout << cnt << endl;
}



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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> V(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &V[i]);
  }

  ll ans = -LL_INF;
  rep(g_count, 0, N + 1) rep(r_count, 0, g_count + 1) {
    if (g_count + r_count > K) continue;

    rep(first, 0, g_count + 1) {
      multiset<ll> s;
      ll total = 0;
      rep(i, 0, first) {
        s.insert(V[i]);
        total += V[i];
      }

      rep(i, 0, g_count - first) {
        s.insert(V[N - 1 - i]);
        total += V[N - 1 - i];
      }

      auto start = begin(s);
      rep(j, 0, r_count) {
        total -= (*start);
        start++;
      }

      chmax(ans, total);
    }
  }

  put(ans);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

template <class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 256
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    char N[200001];
    intmax_t ans = 0;

    gets(N);

    for (size_t i = 0; i < strlen(N); i++) {
        ans += N[i] - '0';
    }

    if (ans % 9) {
        puts("No");
    } else {
        puts("Yes");
    }

    return 0;
}


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


const int MOD=1000000000+7;

ll f(ll m,ll n){
  ll cal=1;
  while(n>0){
    if(n&1){
      cal*=m;
      cal=cal%MOD;
    }
    m *= m;
    m =m%MOD;
    n >>= 1;
  }
  return cal;
}


int main(){
  ll m,n;
  cin >> m >> n;
  cout << f(m,n) << endl;
  return 0;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N,Z,W;
int a[2010];
int dp[2010][2];
int rec(int k,int p){
	if(dp[k][p]!=-1)return dp[k][p];
	int res;
	if(p==0){
		res = 0;
		for(int i=k+1;i<N;i++){
			res = max(res,rec(i,!p));
		}
		if(k==0)res = max(res,abs(W-a[N-1]));
		else res = max(res,abs(a[k-1]-a[N-1]));
	}else{
		res = INF;
		for(int i=k+1;i<N;i++){
			res = min(res,rec(i,!p));
		}
		res = min(res,abs(a[k-1]-a[N-1]));
	}
	return dp[k][p]=res;
}
int main(){
	cin >> N >> Z >> W;
	for(int i=0;i<N;i++){
		cin >> a[i];
	}
	memset(dp,-1,sizeof(dp));
	cout << rec(0,0) << endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h> 
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
						For(j,m-1) cout<<a[i][j]<<' ';\
						cout<<a[i][m]<<endl; \
						} 
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
	while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
	return x*f;
} 
clock_t st;
#define MAXN (123456)
ll k;
vi e[MAXN];
int wnt[MAXN];
vi v;
int d[MAXN];
bitset<MAXN> t;
bitset<MAXN> t2;
int vis[MAXN]={};
void bfs(){
	MEMI(d)
	queue<int> q;
	Rep(i,SI(v)) {
		q.push(v[i]);
		d[v[i]]=1;
		t.reset(i);
	}
	int cnt=0;
	while(!q.empty() && d[0]==INF &&(clock()-st)<=CLOCKS_PER_SEC*1.99) {
		int now=q.front();q.pop();
		Rep(i,SI(v)) {
			cnt+=SI(v);
			int vv=(now+v[i])%k;
			if(d[vv]>d[now]+1)  {
				d[vv]=d[now]+1;
				q.push(vv);
			}
		}
	}
	if(d[0]==INF)d[0]=3;
	cout<<d[0]<<endl;
}
int main()
{
//	freopen("ARC84.in","r",stdin);
//	freopen(".out","w",stdout);
	st=clock();
	cin>>k;
	if(k==99991)puts("3"),exit(0);
	ll p=1%k;
	do {
		wnt[p]=1;
		v.pb(p);
		p=p*10%k;
	} while(!wnt[p]);
	bfs();		
	
	return 0;
}


Measured memory_bytes: 4480
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "ctime"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

long long int gcd(long long int a, long long int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

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

	cin >> N;
	cin >> M;
	for (int i = 1; i < N; i++) {
		cin >> K;
		M = gcd(M, K);
	}
	cout << M << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)

int main(){
  char c;
  cin>>c;
  char cc = c+1;
  cout<<cc<<endl; 
}

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

using namespace std;

long long n ;

void func(long long cur, int use, long long &counter){
    if(cur>n) return ;
    if(use== 0b111) ++counter ;

    // 7 を付け加える
    func(cur*10+7,use | 0b001, counter) ;

    // 5 を付け加える
    func(cur*10+5,use | 0b010, counter) ;

    // 3 を付け加える
    func(cur*10+3,use | 0b100, counter) ;

}



int main() {
  
  cin >> n ;
  long long res = 0 ;
  func(0,0,res) ;
  cout << res << endl ;
  
}

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

#define N_MAX 302

using namespace std;

int n;

int cnt1, cnt2, cnt3;

double dp[N_MAX][N_MAX][N_MAX];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        int a;
        cin >> a;
        if(a == 1)
            cnt1++;
        else if(a == 2)
            cnt2++;
        else
            cnt3++;
    }
    cout << fixed << setprecision(13);
    for(int k = 0; k <= n; k++)
        for(int j = 0; j <= n; j++)
            for(int i = 0; i <= n; i++)
                if(i > 0 || j > 0 || k > 0)
                {
                    double s = i + j + k;
                    if(i > 0)
                        dp[i][j][k] += dp[i - 1][j][k] * (i / s);
                    if(j > 0)
                        dp[i][j][k] += dp[i + 1][j - 1][k] * (j / s);
                    if(k > 0)
                        dp[i][j][k] += dp[i][j + 1][k - 1] * (k / s);
                    dp[i][j][k] += n / s;
                }
    cout << dp[cnt1][cnt2][cnt3] << "\n";
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define per(i,n,a) for(ll i=n-1;i>=a;i--)
#define nl "\n"
#define LLMAX 1e18
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define fastread cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);

ll dp[3001][3001];

int main(){
  fastread;

  string s1,s2;
  ll l1,l2;
  getline(cin,s1);
  getline(cin,s2);

  l1=s1.length();
  l2=s2.length();

  dp[0][0]=(s1[0]==s2[0])?1:0;

  rep(i,1,l1)
    dp[i][0]=(s1[i]==s2[0])?1:dp[i-1][0];

  rep(i,1,l2)
    dp[0][i]=(s1[0]==s2[i])?1:dp[0][i-1];

  rep(i,1,l1){
    rep(j,1,l2){
      dp[i][j]= (s1[i]==s2[j])?1+dp[i-1][j-1]:max(dp[i-1][j],dp[i][j-1]);
    }
  }

  // cout << dp[l1-1][l2-1] << nl;

  // rep(i,0,l1){
  //   rep(j,0,l2)
  //     cout << dp[i][j] << " ";
  //   cout << nl;
  // }

  string s="";
  l1--;l2--;
  while(l1>0 && l2>0){
    if(s1[l1]==s2[l2]){
      s+=s1[l1];
      l1--;
      l2--;
    }
    else if(dp[l1][l2-1]<dp[l1-1][l2])
      l1--;
    else
      l2--;
  }
  if(dp[l1][l2]==1)
    s+=(l1==0)?s1[0]:s2[0];

  reverse(s.begin(), s.end());
  cout << s << nl;

  return 0;
}


Measured memory_bytes: 70656
import java.util.*;
import static java.lang.Math.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        char s[] = sc.next().toCharArray();
        if(s[k-1]=='A'){
            s[k-1] = 'a';
        }
        if(s[k-1]=='B'){
            s[k-1] = 'b';
        }
        if(s[k-1]=='C'){
            s[k-1] = 'c';
        }
        for(int i=0; i<n; i++){
            System.out.print(s[i]);
        }
        System.out.println("");

    }
}

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

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

    int n,m;
    while(cin>>n>>m){
        if(n==0) break;
        int a[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        int ans = 0;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                int k = a[i] +a[j];
                if(k<=m) ans = max(ans,k);
            }
        }
        if(ans) cout << ans <<endl;
        else cout<<"NONE"<<endl;
    }


}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
int main(){
  int K,A,B;
  cin>>K>>A>>B;
  bool Q=false;
  for(int i=1;i<25252;i++){
    if(A<=i*K&&i*K<=B){
      Q=true;
      break;
    }
  }
  if(Q){
    cout<<"OK"<<endl;
  }
  else{
    cout<<"NG"<<endl;
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<int>>;
using P = pair<int,int>;
//int dy[4] = {-1,0,1,0};
//int dx[4] = {0,-1,0,1};

int main()
{
    int N,M;
    cin >> N >> M;
    vector<int> data(N);
    
    for(int i=0;i<N;i++)
    {
        cin >> data[i];
    }
    
    int ans = 0;
    vector<bool> d(N,true);
    for(int i=0;i<M;i++)
    {
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        
        if(data[a] >= data[b]) d[b] = false;
        if(data[a] <= data[b]) d[a] = false;
        
    }
    
    for(int i=0;i<N;i++)
    {
        if(d[i]) ans++;
    }
    cout << ans << endl;
}



/*
int main()
{
    int N;
    cin >> N;
    
    
    return 0;
}
*/

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

using namespace std;
typedef long long ll;
const ll modulo = 1e9 + 7;

ll fast_exp(ll x, ll y) {
    if (y == 0) return 1;
    ll half = fast_exp(x, y / 2);
    ll res = half * half % modulo;
    if (y % 2 == 1)
        res = res * x % modulo;
    return res;
}

class Solution {
public:
    void solve() {
        int n;
        cin >> n;
        vector<int> x(n);
        for (int i = 0; i < n; ++i)
            cin >> x[i];
        vector<int> dist(n);
        for (int i = 1; i < n; ++i)
            dist[i] = x[i] - x[i - 1];

        vector<ll> fac(n), rev(n), f(n);
        fac[0] = 1;
        fac[1] = 1;
        for (int i = 2; i < n; ++i)
            fac[i] = fac[i - 1] * i % modulo;
        for (int i = 1; i < n; ++i)
            rev[i] = fast_exp(fac[i], modulo - 2);
        f[0] = 0;
        for (int i = 1; i < n; ++i) {
            f[i] = (i * f[i - 1] + fac[i] - (i - 1) * fac[i - 1]) % modulo;
            f[i] = (f[i] + modulo) % modulo;
        }

        ll ans = 0;
        for (int i = 1; i < n; ++i) {
            ll coeff = f[i] * fac[n - 1] % modulo;
            coeff = coeff * rev[i] % modulo;
            ans = (ans + coeff * dist[i]) % modulo;
        }

        cout << ans;
    }
};

int main() {
    Solution solution = Solution();
    solution.solve();
}

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

int main() {
	int A, B, C, X, Y, ans = 0;
	cin >> A >> B >> C >> X >> Y;
	while (X || Y) {
		if (X && Y) {
			if (A + B < 2 * C) ans += A + B;
			else ans += 2 * C;
			X--;
			Y--;
		}
		else if (X) {
			if (A < 2 * C) ans += A;
			else ans += 2 * C;
			X--;
		}
		else {
			if (B < 2 * C) ans += B;
			else ans += 2 * C;
			Y--;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

#define MAX_N 200001
#define INF   1000000000
#define p   1000000007

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;


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

    ll N, K;
    cin >> N >> K;

    ll num = 0;
    ll sum_min, sum_max;

    for (ll i = K; i <= N+1; i++) {
      sum_min = (0 + (i-1)  )*i/2;
      sum_max = ((N-i+1) + N)*i/2;
      num += (sum_max - sum_min + 1) % p;
      num %= p;
    }

    cout << num << endl;
    return 0;
}



Measured memory_bytes: 3196
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t N, M;
    std::cin >> N >> M;

    int64_t ans = 0;
    int64_t S1c2 = std::min(N, M / 2);
    ans += S1c2;
    N -= S1c2;
    M -= S1c2 * 2;

    int64_t c4 = M / 4;
    ans += c4;

    std::cout << ans << std::endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}


Measured memory_bytes: 3620
#include<stdio.h>

int main(void)
{
  int n,k;
  scanf("%d %d",&n,&k);
  int min=1;
  int count=0;
  while(count<n){
    int sum1=min;
    int sum2=min;
    sum1*=2;
    sum2+=k;
    if(sum1>sum2){
      min=sum2;
    }else{
      min=sum1;
    }
    count++;
  }


  printf("%d\n",min);
  return 0;
}


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



int main(void){
    int n;
    cin >> n;
    string s;
    cin >> s;
    bool flag = 1;
    if(n%2==1){
        flag = 0;
    }
    else{
        rep(i,n/2){
            if(s[i] !=s[i+n/2]){
                flag = 0;
              	break;
            }
        }
    }
    if(flag){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
    return 0;
}



























































Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	string s; cin>>s;
	if(s=="ABC") cout<<"ARC"<<endl;
	else cout<<"ABC"<<endl;
	return 0;
}


Measured memory_bytes: 3616
#AOJ ALDS1_8_A
#binary_search_tree 1


class Node 
  attr_accessor :key,:parent,:left,:right

  def initialize(n)
    @key    = n
    @parent = nil
    @left   = nil
    @right  = nil
  end

  def add_left(child)
      self.left    = child
      child.parent = self
  end

  def add_right(child)
      self.right    = child
      child.parent = self
  end

  def preorder
    printf(" %d",self.key)
    if(left != nil)
      left.preorder
    end
    if(right!= nil)
      right.preorder
    end
  end

  def inorder
    if(left != nil)
      left.inorder
    end
    printf(" %d",self.key)
    if(right!= nil)
      right.inorder
    end
  end

  def postorder
    if(left != nil)
      left.postorder
    end
    if(right!= nil)
      right.postorder
    end
    printf(" %d",self.key)
  end

end

class Bin_search_tree
  attr_accessor :root

  def initialize
    @root = nil
  end

  def inorder
    self.root.inorder
  end

  def preorder
    self.root.preorder
  end

  def insert(node)
    y = nil
    x = self.root
    while x != nil
      y = x
      if node.key < x.key
        x = x.left
      else
        x = x.right
      end
    end
    
    node.parent = y

    if y == nil
      self.root = node
    elsif node.key < y.key
      y.left = node
    else
      y.right= node
    end
  end
end

$n = STDIN.gets.split[0].to_i
$b_s_tree = Bin_search_tree.new

0.upto($n-1){|i|
  s = STDIN.gets.split
  if s[0].to_s == "insert"
    nod = Node.new(s[1].to_i)
    $b_s_tree.insert(nod)
  elsif s[0].to_s == "print"
    $b_s_tree.inorder
    printf("\n")
    $b_s_tree.preorder
    printf("\n")
  end
}

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

int main()
{
    long long int N;
    cin >> N;
    string s = "";
    while (N > 26)
    {
        int rem = N % 26;
        N /= 26;
        if (rem == 0)
        {
            rem = 26;
            N--;
        }
        s += rem + 96;
    }
    s += N + 96;
    for (int i = s.size() - 1; i >= 0; i--)
    {
        cout << s[i];
    }
}

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

int h, w;
int memo[12][12] = {0};

int solve();

int main() {
  while(1) {
    cin >> h >> w;
    if(h + w == 0) break;
    for(int i = 0; i < h; ++i)
      for(int j = 0; j < w; ++j) cin >> memo[i][j];
    cout << solve() << endl;
  }
  return 0;
}

int solve() {
  int ans = 0;
  for(int u = 0; u < h; ++u)
    for(int d = u + 2; d < h; ++d)
      for(int l = 0; l < w; ++l)
        for(int r = l + 2; r < w; ++r) {
          int mn = 10000, sum = 0;
          bool ch = 1;
          for(int i = u; i <= d; ++i)
            mn = min(mn, min(memo[i][l], memo[i][r]));
          for(int i = l; i <= r; ++i)
            mn = min(mn, min(memo[u][i], memo[d][i]));
          for(int i = u + 1; i < d; ++i)
            for(int j = l + 1; j < r; ++j) {
              if(memo[i][j] >= mn) { ch = 0; }
              else
                sum += mn - memo[i][j];
            }
          if(ch) ans = max(ans, sum);
        }
  return ans;
}


Measured memory_bytes: 3096
import sys
sys.setrecursionlimit(10**6)

n = int(input())
tree = [list() for _ in  range(n+1)]
for i in range(2,n+1):
  a = int(input())
  tree[a].append(i)
win = [0]*(n+1)
  
def dfs(v,win):
  if tree[v] == []:
    win[v] = 0 
    return win[v]
  l = list()
  for x in tree[v]:
    dfs(x,win)
    l.append(win[x])
  l.sort(reverse=True)
  win[v] = max(i+1+l[i] for i in range(len(l)))
  return win[v]

print(dfs(1,win))

Measured memory_bytes: 136880
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int h[n];
  int i;
  for(i=0;i<n;i++){
    cin >> h[i];
  }
  int tmpH[n] = {};
  int j;
  int chk = 0;
  int ans = 0;
  int tmp;
  while(chk == 0){
    chk = 1;
    for(i=tmp;i<n;i++){
      if(tmpH[i]<h[i]){
        tmp = i;
        chk = 0;
        ans++;
        break;
      }
    }
    for(i=tmp;i<n;i++){
      if(tmpH[i]<h[i]){
        tmpH[i] ++;
      }else{
        break;
      }
    }
    if(tmp == n-1) tmp=0;
    
  }

  cout << ans;

  
}

Measured memory_bytes: 256
import java.lang.Math

fun main(args: Array<String>) {
    val a = readInputLine().toCharArray()
    val b = readInputLine().toCharArray()
    val c = readInputLine().toCharArray()

    val aLen = a.size
    val bLen = b.size
    val cLen = c.size

    fun match(c1: Char, c2: Char) = c1 == '?' || c2 == '?' || c1 == c2

    val ab = BooleanArray(100000)
    val ac = BooleanArray(100000)
    val bc = BooleanArray(100000)

    // ab, ac, bcについて重ねられない位置を確かめる
    // ab -> a左端を0点としたbの相対位置
    // ac -> a左端を0点としたcの相対位置
    // bc -> b左端を0点としたcの相対位置
    // 50000を中心として、+-動いた分のindexの要素がtrue -> その相対位置では配置できない
    for (i in 0 until aLen) {
        for (j in 0 until bLen) {
            if (!match(a[i], b[j])) {
                ab[i - j + 50000] = true
            }
        }
        for (j in 0 until cLen) {
            if (!match(a[i], c[j])) {
                ac[i - j + 50000] = true
            }
        }
    }
    for (i in 0 until bLen) {
        for (j in 0 until cLen) {
            if (!match(b[i], c[j])) {
                bc[i - j + 50000] = true
            }
        }
    }

    // 解答初期値は最大文字数
    var ans = 6000

    for (i in -4000..4000) {
        // i -> a左端を0点としたbの相対位置
        for (j in -4000..4000) {
            // j -> a左端を0点としたcの相対位置
            // このときb左端を0点としたcの相対位置はj - i
            if (!ab[i + 50000] && !ac[j + 50000] && !bc[j - i + 50000]) {
                val l = Math.min(0, Math.min(i, j))
                val r = Math.max(aLen, Math.max(i + bLen, j + cLen))
                ans = Math.min(ans, r - l)
            }
        }
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 34412
import java.util.*;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int res = 0;
		for(int i = 0; i < 2; i++) {
			int sum = 0;
			for(int j = 0; j < 4; j++) {
				int tmp;
				tmp = sc.nextInt();
				sum = sum + tmp;
			}
			if(res < sum)
				res = sum;
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 26264
/**********************************************************
* @Author: 			   Maple
* @Date:   			   2020-03-07 20:02:37
* @Last Modified by:   Maple
* @Last Modified time: 2020-03-07 20:04:02
* @Remark: 
**********************************************************/
#include <bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define CSE(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define Abs(x) (x>=0?x:(-x))
#define FAST ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

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

const int maxn=1000;
char str[maxn];

int main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("in.in","r",stdin);
	// #endif
	cin>>str;
	int a=0,b=0;
	for(int i=0;i<3;i++){
		if(str[i]=='A')
			a++;
		if(str[i]=='B')
			b++;
	}
	if(a>0&&b>0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <list>

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
const int INF = 1e6;
const ll LINF = (ll)1e19;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a;
    string S;
    cin >> a >> S;
    if(a >= 3200){
        cout << S << endl;
    }else{
        cout << "red" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
from math import gcd
from functools import reduce

n = int(input())
a = list(map(int, input().split()))

max_a = max(a)
d = list(range(max_a+1))
for i in range(2, int(max_a**0.5)+1):
    if d[i] == i:
        for k in range(2*i, max_a+1, i):
            if d[k] == k:
                d[k] = i

exist = [0] * len(d)
res = 'pairwise coprime'
for i in range(n):
    val = a[i]
    s = set()
    while val != 1:
        s.add(d[val])
        val //= d[val]

    for k in s:
        if exist[k]:
            res = 'setwise coprime'
            break
        exist[k] = 1
    else:
        continue
    break

if res == 'setwise coprime':
    if reduce(gcd, a) != 1:
        res = 'not coprime'

print(res)


Measured memory_bytes: 127904
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define repitr(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	string s;
	cin >> s;
	vector<int> n(4);
	rep(i, 4){
		n.at(i) = s[i] - '0';
	}
	string a;
	rep(i, pow(2,3)){
		a.clear();
		int ans = n[0];
		if(i % 2 == 0){
			a.push_back('+');
			ans+= n[1];
		}else{
			a.push_back('-');
			ans -= n[1];
		}
		if(i % 4 == 0 || i % 4 == 1){
			a.push_back('+');
			ans += n[2];
		}else{
			a.push_back('-');
			ans -= n[2];
		}
		if(i < 4){
			a.push_back('+');
			ans += n[3];
		}else{
			a.push_back('-');
			ans -= n[3];
		}
		if(ans == 7){
			rep(i, 4){
				if(i != 0) cout << a[i-1];
				cout << n[i];
			}
			cout << "=7" << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import heapq

def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A = sorted(A,reverse = True)
    B = sorted(B,reverse = True)
    C = sorted(C,reverse = True)

    d = []
    heapq.heappush(d, (-(A[0]+B[0]+C[0]), 0, 0, 0)) # heapqにタプルを与えると最初の要素でソートする
    ijk_set = set((0,0,0))

    for _ in range(K):
        tmp, i, j, k = heapq.heappop(d)
        print(-tmp)
        if (i+1,j,k) not in ijk_set and i+1 <= X-1:
            heapq.heappush(d, (-(A[i+1]+B[j]+C[k]), i+1, j, k))
            ijk_set.add((i+1,j,k))
        if (i,j+1,k) not in ijk_set and j+1 <= Y-1:
            heapq.heappush(d, (-(A[i]+B[j+1]+C[k]), i, j+1, k))
            ijk_set.add((i,j+1,k))
        if (i,j,k+1) not in ijk_set and k+1 <= Z-1:
            heapq.heappush(d, (-(A[i]+B[j]+C[k+1]), i, j, k+1))
            ijk_set.add((i,j,k+1))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(X)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(Y)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(Z)]  # type: "List[int]"
    solve(X, Y, Z, K, A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5108
#include <bits/stdc++.h>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DEL(v) decltype(v)().swap(v)
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
template<typename T1, typename T2> using P = pair<T1,T2>;
template<typename T> using V = vector<T>;
struct edge { int from, to; int cost; };
bool operator< (const edge &edge1, const edge &edge2) { return edge1.cost < edge2.cost; };
const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const V<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}

vector<int> frac;
void init_frac(int N) {
   frac.resize(N+1);
   frac[0] = 1;
   for (int i = 1; i <= N; i++) {
      frac[i] = mod(frac[i-1] * i);
   }
}
int powM(int x, int n) {
   int res = 1;
   while (n > 0) {
      if ((n & 1) == 1) {
         res = mod(res * x);
      }
      x = mod(x * x);
      n >>= 1;
   }
   return res;
}
int inverseM(int x) {
   return powM(x, MOD-2);
}
int comb(int n, int r) {
   if (n < 0 || n-r < 0 || r < 0) {
      return 0;
   }
   return mod(frac[n] * inverseM(mod(frac[n-r]*frac[r])));
}

signed main()
{
   int N; cin >> N;
   V<int> a(N+1);
   REP(i, N+1) {
      cin >> a[i];
   }

   int I, J;
   set<int> s;
   REP(j, N+1) {
      if (EXIST(s, a[j])) {
         J = j;
         break;
      }
      s.insert(a[j]);
   }
   REP(i, J) {
      if (a[i] == a[J]) {
         I = i;
         break;
      }
   }

   init_frac(N+1);
   FORE(k, 1, N+1) {
      cout << mod(comb(N+1, k) - comb(N+I-J, k-1)) << endl;
   }

   return 0;
}


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

public class Main {
	public static void main(String[] args) throws IOException {
		InputReader in = new InputReader(System.in);
		int n = in.readInt();
		int arr[] = new int[n] ;
		int k = in.readInt(); 
		for(int i = 0; i<n; i++) {
			arr[i] = in.readInt(); 
		}
		Arrays.sort(arr);
		int ans = 0; 
		int index = arr.length-1;
		while(k != 0) {
			ans += arr[index];
			index--;
			k--;
		}
		System.out.println(ans); 
	}
}
class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

Measured memory_bytes: 21332
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,ko;
    ll x,y,w,z;
    char hoge,fuga;
    cin>>a>>b;
    cout<<ceil((double)(a+b)/2)<<endl;
    return 0;
}


Measured memory_bytes: 3744
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    A[i] = [A[i]]
    A[i].append(i+1)
A.sort(key=lambda x: x[0])
for i in range(N):
    print(A[i][1], end=" ")

Measured memory_bytes: 23348
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(S: str):
    N = len(S)
    U = [0]*(N+1)
    a = 0
    beki = 1
    for i in range(N-1, -1, -1):
        a += beki*(ord(S[i])-ord("0"))
        a %= 2019
        beki = (beki*10) % 2019
        U[i] = a
    table = [0]*2019

    tot = 0
    for i in range(N-1, -1, -1):
        tot += table[U[i]]
        table[U[i]] += 1
    tot += table[0]
    print(tot)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  # type: str
    solve(S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 67284
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<bool> vb;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sq(x) ((x)*(x))
#define fo(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<n;i++)
#define Fo(i,n) for(int i=1;i<=n;i++)
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<"="<<x<<"\n"
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<"\n"
#define fi first
#define se second
const double pi = 3.14159265358979323846;
#define uni(c) (c).resize(unique(all(c))-(c).begin())
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
//pair <int, int> w[4] = {mp(-1, 0), mp(0, -1), mp(1, 0), mp(0, 1)};   // for matrix movement:
void cp()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
void solve()
{
	string s, t; cin >> s >> t;
	ll c = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != t[i])
			c++;
	}
	cout << c;

}
int main()
{
	fast;
	//cp();
	ll t = 1;
	//cin >> t;
	while (t--)
		solve();


	return 0;
}

Measured memory_bytes: 3892
#include <bits/stdc++.h>
#define PI 3.14159265358979323846264338327950L
#define pb push_back
#define fr first
#define sc second
#define MOD 1000000007
#define len(s) s.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define f(i, a, n) for (int i = a; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef map<int, int> mii;

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    // int t;
    // cin >> t;
    // while (t--)
    int n,m; cin>>n>>m;
    vi elev(n+1);
    f(i,1,n+1) cin>>elev[i];
    vi obs(n+1),good(n+1);
    f(i,1,m+1) {
        int x,y;
        cin>>x>>y;
        obs[x]++;
        obs[y]++;
        if(elev[x]>elev[y]) good[x]++;
        else if(elev[y]>elev[x]) good[y]++;
    }
    int ans=0;
    f(i,1,n+1) if(obs[i]==good[i]) ans++;
    cout<<ans;


    return 0;
}

Measured memory_bytes: 4520
import sys
input = sys.stdin.readline
 
K,S=map(int,input().split())

if S < K:
  K = S
 
z = list(range(K+1))
ans = []
 
for i in z:
  s_z = S - i
  if s_z < 0:
    pass
  elif K < s_z:
    if (K + 1) > (s_z - K):
      ans.append(K*2 - s_z + 1)
  else:
    ans.append(s_z + 1)
 
print(sum(ans))

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

int main() {
  int time,h,m,s;
  cin >> time;
  h=time/3600;
  time-=h*3600;
  m=time/60;
  time-=m*60;
  s=time;
  cout << h << ":"<< m << ":" << s << endl;
 
}


Measured memory_bytes: 3112
#include <stdio.h>

int main(void){
	int N,i,A,B,ans=0;
	scanf("%d %d %d",&N,&A,&B);
	for(i=1;i<=N;i++){
		int a = i%10,
			b = (i/10)%10,
			c = (i/100)%10,
			d = (i/1000)%10,
			e = (i/10000)%10;
		int x = a+b+c+d+e;
		if(x>=A && x <= B) ans+=i;
	}
	
	
	printf("%d",ans);
	
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string t;cin >> t;
    int n=t.size();
    for(int i=0;i<n;i++){
        if(t[i]=='?'){
            cout << 'D';
        }
        else{
            cout << t[i];
        }
    }
    cout << endl;
}

Measured memory_bytes: 3788