akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){
  long n,k,ii;
  long ans = 0,pos;
  cin >> n >> k;
  vector<long> a;
  a.resize(n);

  for(ii=0;ii<n;ii++){
	cin >> a[ii];
  }

//  ans = n / (k-1) ;
//  if(n != k ){
//	cout << ans << endl;
//  }
//  else{
//	cout << 1 << endl;
//  }

  pos = 1;
  while(pos <= n - 1 ){
	pos += (k - 1);
	ans ++ ;
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
	long long n,a,b;
	cin>>n>>a>>b;
	long long y,s,sum;
	s=n/(a+b);
	y=n%(a+b);
	if(a<=y)
		sum=s*a+a;
	else
		sum=s*a+y;
		
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=n-1;i>=0;i--){
        cout<<a[i];
        if(i!=0)cout<<" ";
        
    }cout<<endl;
    return 0;
}


Measured memory_bytes: 3084
# https://atcoder.jp/contests/abc166/submissions/12754173

def abc166_e():
    _ = int(input())
    A = list(map(int, input().split()))
    ans = 0
    from collections import defaultdict
    d = defaultdict(int)
    for i, x in enumerate(A, 1):
        ans += d[i - x]
        d[x + i] += 1
    print(ans)

abc166_e()

Measured memory_bytes: 61428
#include <iostream>
#include <string>

using namespace std;

int main() {
	int n, t;
	cin >> n >> t;
	string eki[10];
	int ekii[10];
	int counter = 0;
	string pss, pas, nss, nas;
	int pst, pat, nsh, nsm, nah, nam;
	char c;
	for (int i = 0; i < n; i++) {
		cin >> nsh >> c >> nsm >> nss >> nah >> c >> nam >> nas;
		if (i == 0) {
			pst = nsh * 60 + nsm;
			pat = nah * 60 + nam;
			pss = nss;
			pas = nas;
		} else {
			if ((nsh * 60 + nsm) - pat >= t) {
				eki[counter] = nss;
				ekii[counter] = (nsh * 60 + nsm) - pat;
				counter++;
			}
			pst = nsh * 60 + nsm;
			pat = nah * 60 + nam;
			pss = nss;
			pas = nas;
		}
	}
	if (counter == 0) {
		cout << 0 << endl;
	} else {
		cout << counter << endl;
		for (int i = 0; i < counter; i++) {
			cout << eki[i] << " " << ekii[i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
     
     using namespace std;
     
    int main(){
      int n;
    	map<string,int> m;
      string arr[3]={"Sunny","Cloudy","Rainy"};
      m["Sunny"]=0;
      m["Cloudy"]=1;
      m["Rainy"]=2;
      
      string s;
      cin>>s;
      n=m[s];
      cout<<arr[(n+1)%3];
      
      
      
     
    return 0;
    }

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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double PI = (3.141592653589794);
const double EPS = (0.0000000001);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }



//----------------------------------------------------------------
int nmax=200000; // 2*(10^5)
vvec g(nmax);





void solve4ts()
{
    
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vec b(n);
    vec c(n);
    map<int,int> mp;
    map<int,int> ro;
    rep(i,n){
        b[i]=(a[i]+i)*(-1);
        c[i]=a[i]-i;
        mp[c[i]]++;
    }
    int cnt=0;
    rep(i,n){
        ro[c[i]]++;
        cnt+=mp[b[i]]-ro[b[i]];
    }
    cout<<cnt<<endl;
}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
    int repeat = 1;
    // cin >> repeat;
    while(repeat--) solve4ts();
}

Measured memory_bytes: 58080
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}


int main(){
	ll n,k;
	cin>>n>>k;
	if(n==1 && k==1){
		cout<<1<<endl;
	}else if(n==1){
		cout<<k-2<<endl;
	}else if(k==1){
		cout<<n-2<<endl;
	}else if(n<3 || k<3){
		cout<<0<<endl;
	}else{
		cout<<(n-2)*(k-2)<<endl;
	}
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 300500;
int n,m,q,mo,fa[N],A[N],B[N],C[N],g,z;
bool ok[2][1020000];
int gcd(int a, int b){return !b?a:gcd(b,a%b);}
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
void merge(int x, int y){
	x=find(x);y=find(y);fa[x]=y;
}
int getid(int x, int p, int q){//01 012
	return 6*(x-1)+p*3+q+1;
}
int main() {
	read(n);read(m);read(q);read(mo);
	rep(i,1,m){
		read(A[i]);read(B[i]);read(C[i]);
		g=gcd(g,C[i]-C[1]>0?C[i]-C[1]:-(C[i]-C[1]));
	}
	g=gcd(g,mo);mo=gcd(3*g,mo);
	z=C[1]%g;
	rep(i,1,n*6)fa[i]=i;
	for(int x=z%mo,cnt=0;cnt<=mo;cnt++){
		ok[0][x]=1;x=2LL*x%mo;ok[1][x]=1;x=2LL*x%mo;
	}
	rep(i,1,m){
		int u=A[i],v=B[i],w=(C[i]-z)/g;
		rep(p,0,1)rep(q,0,2)merge(getid(u,p,q),getid(v,p^1,(2*q+w)%3));
		swap(u,v);
		rep(p,0,1)rep(q,0,2)merge(getid(u,p,q),getid(v,p^1,(2*q+w)%3));
	}
	while(q--){
		int s,t,r;read(s);read(t);read(r);bool res=0;
		rep(p,0,1)rep(q,0,2)
			if(find(getid(t,0,0))==find(getid(s,p,q))){
				res|=ok[p][((r+z-q*g)%mo+mo)%mo];
			//	if(ok[p][((r+z-q*g)%mo+mo)%mo])cerr<<p<<' '<<((r+z-q*g)%mo+mo)%mo<<endl;
			}
		printf("%s\n",res?"YES":"NO");
	}
	return 0;
}


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

int getElement(long int num)
{
  int sqrtNum;
  sqrtNum = (int)std::sqrt(num);

  int i;
  for (i = sqrtNum; i > 0; i--)
    {
      if(num % i == 0)
	{
	  return i;
	}
    }
  return -1;
}


int main()
{
  long int inputNum;
  cin >> inputNum;

  long int element1, element2;
  element1 = getElement(inputNum);
  element2 = inputNum / element1;

  //cout << inputNum << " " <<  element1 << " " << element2 << endl;
  long int ans = (element1 - 1) + (element2 - 1);
  cout << ans << endl;

  return 0;
}
	  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

bool ok[1001001];

struct Edge {
  ll from;
  ll to;
  ll cost;
};
const long long INF = 1LL << 60;
/* Bellman-Ford(N,edges,dis,loop)
  入力：頂点数 N, 辺の集合 edges, 距離を格納する dis, 負のループの存在 loop
  計算量：O(|E|×|V|)
  開始点は 0
  副作用：dis,loopが書き換えられる
*/
void bellmanford(int N, const vector<Edge> &edges, vl &dis, bool &loop) {
  int M = edges.size();
  dis.resize(N, INF);
  dis[0] = 0;
  rep(i, N) rep(j, M) {
    Edge e = edges[j];
    if(!ok[e.to] || !ok[e.from]) continue;
    if(dis[e.to] > dis[e.from] + e.cost) {
      dis[e.to] = dis[e.from] + e.cost;
      if(i == N - 1) {
        loop = true;  //負のループがある
        break;
      }
    }
  }
}

int main() {
  ll n, m, p;
  cin >> n >> m >> p;
  vector<Edge> edges;
  vector<vl> g(n), rg(n);
  rep(i, m) {
    Edge e;
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    e.from = a;
    e.to = b;
    e.cost = p - c;
    edges.push_back(e);
    g[a].push_back(b);
    rg[b].push_back(a);
  }
  queue<int> q;
  vb ok1(n, false);
  q.push(0);
  ok1[0] = true;
  while(!q.empty()) {
    int i = q.front();
    q.pop();
    for(auto v : g[i]) {
      if(ok1[v]) continue;
      ok1[v] = true;
      q.push(v);
    }
  }
  vb ok2(n, false);
  q.push(n - 1);
  ok2[n - 1] = true;
  while(!q.empty()) {
    int i = q.front();
    q.pop();
    for(auto v : rg[i]) {
      if(ok2[v]) continue;
      ok2[v] = true;
      q.push(v);
    }
  }
  rep(i, n) ok[i] = ok1[i] & ok2[i];
  vl d;
  bool loop;
  bellmanford(n, edges, d, loop);
  cout << (loop ? -1 : max(0LL, -d[n - 1])) << endl;
}

Measured memory_bytes: 3988
# -*- coding: utf-8 -*-
X, K, D = map(int, input().split())
X = abs(X)

if X - K*D >= 0:
  print(X - K*D)
  exit()
else:
  a = X // D
  if (K - a) % 2 == 0:
    print(X % D)
  else:
    print(abs(X % D - D))

Measured memory_bytes: 61752
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<utility>
#define rep(i,a) for( int i = 0; i != (a); ++i )

const int INF = 1 << 30;

typedef std::pair<int, int> P;

int n, m;
int dp[200];

int main()
{
	while( scanf( "%d", &n ), n )
	{
		memset( dp, 0, sizeof( dp ) );

		std::vector<P> ps;
		rep( i, n )
		{
			int h, r;
			scanf( "%d%d", &h, &r );
			ps.push_back( P( h, r ) );
		}

		scanf( "%d", &m );
		rep( i, m )
		{
			int h, r;
			scanf( "%d%d", &h, &r );
			ps.push_back( P( h, r ) );
		}

		std::sort( ps.begin(), ps.end() );

		int ans = 0;
		rep( i, ps.size() )
		{
			dp[i] = 1;
			
			rep( j, i )
				if( ps[i].first > ps[j].first && ps[i].second > ps[j].second )
					dp[i] = std::max( dp[i], dp[j]+1 );

			ans = std::max( ans, dp[i] );
		}

		printf( "%d\n", ans );
	}

	return 0;
}

Measured memory_bytes: 1040
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;
long long INF = pow(10,9)+1;
int main(){
  int N;
  int M;
  int L;
  cin >> N;
  cin >> M;
  cin >> L;
  int fuel[N][N];
  int dist[N][N];
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      fuel[i][j] = INF;
    }
  }
  for(int i = 0; i < N; i++){
    fuel[i][i] = 0;
  }
  for(int i = 0; i < M; i++){
    long long a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    fuel[a][b] = c;
    fuel[b][a] = c;
  }
  
  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        if(fuel[i][k] + fuel[k][j] < fuel[i][j]){
          fuel[i][j] = fuel[i][k] + fuel[k][j];
          fuel[j][i] = fuel[i][k] + fuel[k][j];
        }
      }
    }
  }
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      if(fuel[i][j] <= L){
        dist[i][j] = 1LL;
      }else{
        dist[i][j] = INF;
      }
    }
  }
  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        if(dist[i][k] + dist[k][j] < dist[i][j]){
          dist[i][j] = dist[i][k] + dist[k][j];
        }
      }
    }
  }

  int Q;
  cin >> Q;
  for(int i = 0; i < Q; i++){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if(dist[a][b] == INF){
      cout << -1 << endl;
      continue;
    }
    cout << dist[a][b] - 1 << endl;
  }

}

Measured memory_bytes: 1280
S=sorted(list(set(list(input()))))
alph=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
sum=0
A="None"
for i in range(len(S)):
    if S[i]!=alph[i]:
        A=alph[i]
        break
if A=="None" and len(S)<26:
    A=alph[i+1]

print(A)



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

int main(void){
    int a, b;
    
    while(1){
        cin >> a >> b;
        if(a == 0 && b == 0) break;
        
        if(a < b){
            cout << a << " " << b << endl;
        }else{
            cout << b << " " << a << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3096
// https://atcoder.jp/contests/abc154/tasks/abc154_c

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 200000;
const int A_I_MAX = 1e9;

int N;
int A[N_MAX];

void solve() {
  sort(A, A + N);
  REP(i, N - 1) {
    if (A[i] == A[i + 1]) {
      puts("NO");
      return;
    }
  }
  puts("YES");
}

void input() {
  scanf("%d", &N);
  REP(i, N) scanf("%d", A + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

const int MOD = 1e9 + 7;
const int SIZE = 1e5 + 10;

int main() {
	int N, M;
	int fct[SIZE];

	cin >> N >> M;

	fct[0] = 1;
	for (int i = 1; i < SIZE; ++i)
		fct[i] = (1LL * fct[i-1] * i)%MOD;
	if (N - M == 0)
		printf("%d\n", (((1LL*fct[M] * fct[N]) % MOD)*2) % MOD);
	else if(N-M == -1 || N-M == 1)
		printf("%d\n", (1LL * fct[N] * fct[M]) % MOD);
	else
		printf("0\n");

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <climits>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll L,R,Ans=LLONG_MAX;
	cin>>L>>R;
	for(ll i=L;i<=min(R,L+2030);i++){
		for(ll j=L;j<=min(R,L+2030);j++){
			if(i==j) continue;
			ll tmp=i*j;
			Ans=min(Ans,tmp%2019);
		}
	}
	cout<<Ans<<endl;
	return 0;
}

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

int main() {
  int n,m,sum=0;
  cin>>n>>m;
  int a[n];
  for(int i=0;i<n;i++){
    int l;
    cin>>l;
    a[i]=l;
    sum+=l;
  }
  sort(a,a+n);
  if(a[n-m]*4*m<sum)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
/*
ID: leihaow1
TASK: 
LANG: C++              
*/ 
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,m,k,a,b,c[10001];
int main(){
	scanf("%d%d",&n,&m);
	while (n--){
		scanf("%d%d",&a,&b);
		if (b>m) continue;
		else{
			c[++k]=a;
		}
	}
	sort(c+1,c+1+k);
	if (!c[1]) cout<<"TLE";
	else cout<<c[1];
	return 0;
}

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

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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;


#define rep(i,n) for(ll i=0;i<n;i++)



int main() {


  cout<<fixed<<setprecision(10);

  string str; cin>>str;
  ll q; cin>>q;

  rep(i,q){
    string order; cin>>order;

    if(order == "print"){
      ll a,b; cin>>a>>b;

      cout<<str.substr(a, b-a+1)<<endl;
    }else if(order == "reverse"){
      ll a,b; cin>>a>>b;
      reverse(str.begin()+a, str.begin()+b+1);
    }else{
      ll a,b; cin>>a>>b;
      string p; cin>>p;

      for(ll i=a; i<=b; ++i){
        str[i] = p[i-a];
      }
    }
  }

}




//






Measured memory_bytes: 3220
#include <stdio.h>

typedef struct { int x, y; } point_t;
typedef struct { point_t p0, p1; } segment_t;

static int get_type(segment_t s1, segment_t s2) {
  int k, l, m, n;

  k = s1.p0.x - s1.p1.x;
  l = s1.p0.y - s1.p1.y;
  m = s2.p0.x - s2.p1.x;
  n = s2.p0.y - s2.p1.y;
  if (k * n == l * m) return 2;
  if (-(k * m) == l * n) return 1;
  return 0;
}

int main(int argc, char **argv) {
  int q, i;
  segment_t s1, s2;

  scanf("%d", &q);
  for (i = 0; i < q; ++i) {
    scanf("%d %d %d %d %d %d %d %d",
        &s1.p0.x, &s1.p0.y, &s1.p1.x, &s1.p1.y,
        &s2.p0.x, &s2.p0.y, &s2.p1.x, &s2.p1.y);
    printf("%d\n", get_type(s1, s2));
  }
}


Measured memory_bytes: 2112
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

      int sun = 0;
      for(int i = 0 ; i <= n ; i++){
      	int count = 0;
        int p = i;
        while(true) {
        	count += p % 10;
          p = p / 10;
          if ( p == 0) {
          	if ( count >= a && count <= b) {
            	sun += i;
            }
            break;
          }
          
        }
      }
      
		System.out.println(sun);
	}
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< long double, long double > pdd;
typedef pair< long long, long long > pll;

#define vec vector
#define ALL(x) begin(x), end(x)

const int inf = 1e9;
const ll inf64 = 1e18;

const int N = 1e6 + 5;

int n;
char s[N];
int q;
int k[100];
ll res[100];

struct Queue {
    queue< ll > que;
    queue< int > pos;
    ll all = 0;
    int mx = 0;
    int sz = 0;
    ll sum = 0;
    int cur_pos = -1;

    Queue() = default;

    Queue(int _mx):
        all(0), mx(_mx), sz(0), sum(0), cur_pos(-1)
    { }

    void add() {
        pos.push(++cur_pos);
        que.push(-all);
        sum -= all;
        sz++;
        while(cur_pos - pos.front() + 1 > mx) {
            sum -= que.front();
            que.pop();
            pos.pop();
            sz--;
        }

        if(!sz) {
            sum = all = 0;
        }
    }

    void inc_pos() {
        cur_pos++;
        while(!pos.empty() && cur_pos - pos.front() + 1 > mx) {
            sum -= que.front();
            que.pop();
            pos.pop();
            sz--;
        }

        if(!sz) {
            sum = all = 0;
        }
    }

    void inc(ll val) {
        all += val;
    }

    ll get() const {
        return sum + all * sz;
    }

    void show() {
        for(int i = 0;i < sz;i++) {
            cout << pos.front() << " ";
            pos.push(pos.front());
            pos.pop();
        }
        cout << ", sum = " << sum << ", all = " << all << ", tot = " << sum + all * sz << " ";
    }
} qq[100];

int main() {

#ifdef debug
    freopen("input.txt", "r", stdin);
#endif

    scanf("%d %s", &n, s);
    scanf("%d", &q);

    for(int i = 0;i < q;i++) {
        scanf("%d", &k[i]);
        qq[i] = Queue(k[i]);
    }

    for(int i = 0;i < n;i++) {
        if(s[i] == 'D') {
            for(int j = 0;j < q;j++) {
                qq[j].add();
            }
        }else if(s[i] == 'M') {
            for(int j = 0;j < q;j++) {
                qq[j].inc(1);
                qq[j].inc_pos();
            }
        }else if(s[i] == 'C') {
            for(int j = 0;j < q;j++) {
                qq[j].inc_pos();
                res[j] += qq[j].get();
            }
        }else {
            for(int j = 0;j < q;j++) {
                qq[j].inc_pos();
            }
        }

//        cout << i << " : { ";
//        qq[0].show();
//        cout << "}\n";
    }

    for(int j = 0;j < q;j++) {
        printf("%lld\n", res[j]);
    }

    return 0;
}


Measured memory_bytes: 464144
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;
    cin>>s;
    string a = s.substr(5,2);
    string b = s.substr(8,2);
    if(a <= "04" && b <= "30"){
        cout<<"Heisei";
    } else {
        cout<<"TBD";
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String s = new String(br.readLine());
        long total = 0, bit;
        int lOprIndex, rOprIndex;
        String tmp = new String();
        for(int i=0; i<Math.pow(2, s.length()-1); i++){
            lOprIndex = 0;
            rOprIndex = 1;
            for(bit=i; bit!=0; bit=bit>>1){
                if((bit&1) == 1){
                    tmp = s.substring(lOprIndex, rOprIndex);
                    total += Long.parseLong(tmp.toString());
                    lOprIndex = rOprIndex;
                }
                rOprIndex++;
            }
            tmp = s.substring(lOprIndex, s.length());
            total += Long.parseLong(tmp.toString());
        }
        System.out.println(total);
    }
}

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

long long n, a, b, num[300005];

LL minn(LL x, LL y)
{
	if(x>y) return y;
	return x;
}

int main()
{
	scanf("%lld%lld%lld", &n, &a, &b);
	if(a*b<n || a+b-1>n)
	{
		printf("-1\n");
		return 0;
	}
	int h=0;
	num[0]=1-b;
	for(int i=1; i<=n-a; i++)
	{
		if(!h)
		{
			h=minn(n-i-a+1, b-1);
			num[i]=num[i-1]+b+h;
			a--;
		}
		else
		{
			h--;
			num[i]=num[i-1]-1;
		}
	}
	for(int i=n-a+1; i<=n; i++) num[i]=i;
	for(int i=1; i<=n; i++)printf("%d ", num[i]);
}

Measured memory_bytes: 4480
from collections import Counter, defaultdict

def main():
    data = list(input())
    mod = 10 ** 9 + 7

    q_num = data.count('?')

    dp = [[0 for i in range(13)] for i in range(len(data) + 1)]
    dp[0][0] = 1

    for i in range(1, len(data) + 1):
        now_ele = data[i - 1]
        if now_ele == '?':
            for j in range(13):
                for k in range(10):
                    amari = (j * 10 + k) % 13
                    dp[i][amari] += dp[i - 1][j]
                    dp[i][amari] %= mod
        else:
            now_ele = int(now_ele)
            for j in range(13):
                amari = (j * 10 + int(now_ele)) % 13
                dp[i][amari] += dp[i - 1][j]
                dp[i][amari] %= mod
        # print(dp[i])

    ans = dp[len(data)][5]
    print(ans)



if __name__ == '__main__':
    main()
    # test()


Measured memory_bytes: 69640
#include <stdio.h>

int main(void) {
  int n, d, can, people;
  scanf("%d %d", &n, &d);
  can = 2*d + 1;  //１人で監視できる本数
  if (n%can==0) {
    people = n / can;
  } else {
    people = n / can + 1;
  }
  printf("%d\n", people);

  return 0;
}


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

int main() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    a += b;
    c += d;
    if(a ==c ){
        std::cout << "Balanced" << std::endl;
    }else if(a < c){
        std::cout << "Right" << std::endl;
    }else{
        std::cout << "Left" << std::endl;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define PI 3.141592653589793
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const ll INF = 1LL << 56;

//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    ll x,k,d;
    cin >> x >> k >> d;
    x=abs(x);
    ll c=x/d;
    if (k<c){
        x-=k*d;
        cout << x << endl;
        return 0;
    }
    x%=d;
    k-=c;
    if (k%2){
        x-=d;
        x=abs(x);
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    long long x = accumulate(a.begin(), a.end(), 0LL);
    long long ans = LLONG_MAX;
    for(int i=0; i<n-1; ++i){
        x -= a[i] * 2;
        ans = min(ans, abs(x));
    }
    cout << ans << endl;

    return 0;
}


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

const int mod = 1000000007;
//const int mod = 998244353;
const int INF = 1001001001;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> a(2, vector<int> (n));
    rep(i, 0, 2) rep(j, 0, n) cin >> a[i][j];
    vector<vector<int>> b(2, vector<int> (n));
    int sum = 0;
    rep(i, 0, n){
        sum += a[0][i];
        b[0][i] = sum;
    }
    sum = 0;
    rep(i, 0, n) sum += a[1][i];
    b[1][0] = sum;
    rep(i, 1, n){
        b[1][i] = sum - a[1][i-1];
        sum -= a[1][i-1];
    }
    vector<int> c(n);
    rep(i, 0, n) c[i] = b[0][i] + b[1][i];
    int ans = 0;
    rep(i, 0, n) ans = max(ans, c[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;


void Main(){
    ll N;
    string s;
    map<string, ll> counter;
    map<ll, set<string>> inv_counter;
    // set<ll, vector<ll>, greater<ll>> nums; 
    sll(N);

    rep(i, N){
        cin >> s;
        counter[s]++;
    }

    ll max_num = -1;
    for(auto &p:counter){
        max_num = max(max_num, p.second);
        inv_counter[p.second].insert(p.first);
    }

    for(auto &ss: inv_counter[max_num]){
        cout << ss <<endl;
    }
    
}

int main(){
    Main();
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int max_num = (n-1)*(n-2)/2;
    if(k > max_num){
        cout << -1 << endl;
        return 0;
    }
    vector<P> ans;
    for(int i = 2; i <= n; i++){
        ans.emplace_back(1, i);
    }
    for(int i = 1; i < n; i++){
        for(int j = 1; j < i; j++){
            ans.emplace_back(j+1, i+1);
            max_num--;
            if(max_num == k) break;
        }
        if(max_num == k) break;
    }
    cout << ans.size() << endl;
    for(auto &p : ans){
        cout << p.first << " " << p.second << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
typedef long long LL;
LL gcd(LL a, LL b)
{
	return b ? gcd(b, a%b) : a;
}
int main()
{
	LL N, X;
	scanf("%lld%lld", &N, &X);
	printf("%lld\n", 3*(N-gcd(N,X)));
}


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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

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

    int a, b;
    cin >> a >> b;
    cout << a * b << " " << 2 * (a + b) << endl;

}

Measured memory_bytes: 3136
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;

int main(){
    while(true){
        int d, e;
        cin >> d;
        cin >> e;
        
        if(d == 0 && e == 0)
            break;
        
        int D;
        double rD;
        double x;
        double ans;
        int ix;
        int A;
        double rA;
        
        D = e*e*2 - d*d;
        if(D > 0)
            rD = sqrt( D );
        else
            rD = 0;
        
        x = ( d - rD ) / 2;
        if(x > 0)
            ix = ( d - rD ) / 2;
        else{
            ix = 0;
            x = 0;
        }
        
        A = ix*ix + (d-ix)*(d-ix);
        rA = sqrt( A );
        ans = rA - e;
        if(ans < 0)
            ans = -ans;
        
        if(x > ix){
            int A2;
            double rA2;
            double ans2;
            ix ++;
            A2 = ix*ix + (d-ix)*(d-ix);
            rA2 = sqrt( A2 );
            ans2 = rA2 - e;
            if(ans2 < 0)
                ans2 = -ans2;
            if(ans2 < ans)
                ans = ans2;
        }
        
        cout << ans <<endl;
    }
}
    

Measured memory_bytes: 3276
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
const ll N = 300, INF = N * 1'000'000'000;
ll d[N+1][N+1], a[N+1][N+1];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m, l;
    cin >> n >> m >> l;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            d[i][j] = INF;
        }
    }
    for(int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        d[a][b] = d[b][a] = c;
    }
    for(int k = 1; k <= n; k++) {
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            a[i][j] = d[i][j] <= l ? 1 : INF;
        }
    }
    for(int k = 1; k <= n; k++) {
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
            }
        }
    }
    int q;
    cin >> q;
    while(q--) {
        int s, t;
        cin >> s >> t;
        cout << (a[s][t] == INF ? -1 : a[s][t] - 1) << endl;
    }
    return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,c=0,j;
    string s;
    cin>>s;
    for(i=0,j=s.size()-1;i<s.size()/2;i++,j--)
    {
        if(s[i]!=s[j])
            c++;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3568
i=lambda:map(int,input().split())
h,w,n=i()
r=[0,1,2]
d={} 
while n:
    a,b=i();n-=1
    for j in r:
        for k in r:
            if w>=b+k>2<a+j<=h:d[(a+j,b+k)]=d.get((a+j,b+k),0)+1
c=[0]*10
for i in d:c[d[i]]+=1
c[0]=(h-2)*(w-2)-sum(c)
print(*c,sep="\n")

Measured memory_bytes: 166488
import math

def Isprime(x):
    if x == 2:
        return True
    i = 2
    while(i <= math.sqrt(x)):
        if(x%i==0):
            return False
        i += 1
    return True

n = int(input())

i = 0
count = 0
while(n>i):
    a = int(input())
    if(Isprime(a)==True):
        count += 1
    i += 1
print(count)

Measured memory_bytes: 7804
#include<cstdio>
#include<algorithm>
#include<vector>
#include<deque>
#include<stack>
#include<queue>
#include<string>
#include<iostream>
#include<tuple>
#include<utility>
#include<set>
#include<queue>
#include<iomanip>
#include<iterator>
#include<map>
#include<bitset>
#include<array>
#include<cmath>
#include<functional>
#include<list>
using namespace std;
typedef long long int llint;
typedef long double lldo;
const llint big=2e15+100000;
const int mod=1e9+7;
const lldo eps=1e-7;
const long double pai=3.141592653589793238462643383279502884197;
#define mt make_tuple
#define mp make_pair
#define fir first
#define sec second
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define res resize
#define ins insert
#define era erase
#define dme(in) cout<<in<<endl;return 0
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
class dinic{
public:
	int n,sta,gol;
	vector<vector<llint>> hen;
	vector<int>dis;//bfsの距離
	//隣接行列(O(VVE)なので)
	dinic(int in,int s,int g){
		n=in;
		sta=s;
		gol=g;
		hen.res(in);
		dis.res(in);
		for(int i=0;i<n;i++){hen[i].res(in);}
	}
	void add(int u,int v,llint wei){hen[u][v]+=wei;}
	//隣接なので逆編情報が不要!!
	//増加のbfsする
	//それが増加する向きだけに流す
	//流れないなら、終了!
	void bfs(void){
		int i;
		for(i=0;i<n;i++){dis[i]=-1;}//初期化
		queue<pair<int,int>>que;
		que.push(mp(0,sta));
		dis[sta]=0;
		while(!que.empty()){
			
			int kyo=que.front().fir;
			int town=que.front().sec;
			que.pop();
			for(i=0;i<n;i++){
				if(hen[town][i]!=0&&dis[i]==-1){dis[i]=kyo+1;que.push(mp(kyo+1,i));}
			}
		}
	}
	llint dfs(int ter,llint lim){
		//それまでの上限がlim
		//流した量を返す
		if(ter==gol){return lim;}
		llint ans=0;
		int i;
		for(i=0;i<n;i++){
			if(dis[ter]>=dis[i]||hen[ter][i]==0){continue;}//dinic
			if(lim==ans){break;}
			llint nga=dfs(i,min(lim-ans,hen[ter][i]));
			ans+=nga;
			hen[ter][i]-=nga;
			hen[i][ter]+=nga;
		}
		return ans;
	}
	llint solve(void){
		llint ans=0;
		while(-1){
			bfs();
			llint nga=dfs(sta,big);
			ans+=nga;
			if(nga==0){break;}
		}
		return ans;
	}
};
int main(void){
	int n,i,j;cin>>n;
	dinic gra(n+2,0,n+1);
	//燃やす埋める問題
	//最小フロー最大カット
	llint mra=0;//初めにもらう分
	//0と同じ側=割る
	//n+1側=残す
	for(i=1;i<=n;i++){
		llint a;cin>>a;
		if(a<0){gra.add(0,i,-a);}
		else{mra+=a;gra.add(i,n+1,a);}
	}
	for(i=1;i<=n;i++){
		for(j=i+i;j<=n;j+=i){gra.add(i,j,big);}
	}
	cout<<mra-gra.solve()<<endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std ;
int main()
{
    char arr[55];
    int n,x;
    cin >> n >> x ;
    scanf("%s",arr);
    arr[x-1]=arr[x-1]+32;
    cout << arr << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];


int main(){
    long long a,b;
    cin>>a>>b;
    vector<long long> dp(a+1,INF);
    dp[0]=0;
    rep(i,b){
        long long k,l;
        cin>>k>>l;
        rep(j,a){
            long long dm=min(j+k,a);
            dp[dm]=min(dp[dm],dp[j]+l);
        }
    } 
    cout<<dp[a]<<endl;
   
    
}



Measured memory_bytes: 384
/**
*    author:  yuya1234
*    created: 03.09.2020 13:17:54
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
long double eps = 1.0E-14;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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; }
template<class T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T>T lcm(T a,T b){return gcd(a,b)*(a/gcd(a,b))*(b/gcd(a,b));}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(15);

  int n;
  cin>>n;

  int *a=new int[100001];
  int *b=new int[100001];

  REP(i,100001)
  {
    a[i]=b[i]=0;
  }

  int tmp;
  REP(i,n)
  {
    cin>>tmp;
    if(i%2==0)a[tmp]++;
    else b[tmp]++;
  }

  int max11,max12,max21,max22;
  max11=max12=max21=max22=0;

  int idx11,idx12,idx21,idx22;
  idx11=idx12=idx21=idx22=0;

  FOR(i,1,100000)
  {
    if(chmax(max11,a[i])){max21=a[idx11];idx21=idx11;idx11=i;}
    else if(chmax(max21,a[i]))idx21=i;
  }

  FOR(i,1,100000)
  {
    if(chmax(max12,b[i])){max22=a[idx12];idx22=idx12;idx12=i;}
    else if(chmax(max22,b[i]))idx22=i;
  }

  int ans=0;
  if(idx11!=idx12)ans=n-max11-max12;
  else ans=n-max(max11+max22,max21+max12);

  cout<<ans<<endl;



  return 0;
}

Measured memory_bytes: 4472
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	num := make([]bool, 1000000)

	for sc.Scan() {
		var nmpr int

		n, _ := strconv.Atoi(sc.Text())

		lmt := int(math.Sqrt(float64(n)))

		for i := 2; i <= lmt; i++ {
			for j := 2; i*j <= n; j++ {
				if !num[i*j] {
					num[i*j] = true
				}
			}
		}

		for t := 2; t <= n; t++ {
			if !num[t] {
				nmpr++
			}
		}

		fmt.Println(nmpr)
	}

}



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

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(void){
    int n;
    cin >> n;
    vector<int> d(n);
    for(auto& i : d) cin >> i;
    sort(d.begin(), d.end());
    cout << (d.at(n/2)-d.at(n/2-1)) << endl;
    return 0;
}


Measured memory_bytes: 640
from functools import lru_cache
import sys
sys.setrecursionlimit(10**9)
n = int(input())
arr = [int(i) for i in input().strip().split()]

@lru_cache(None)
def cal(i):
    if i>=n-1:
        return 0
    else:
        if i==n-2:
            return cal(i+1)+abs(arr[i]-arr[i+1])

        return min(cal(i+1)+abs(arr[i]-arr[i+1]),cal(i+2)+abs(arr[i]-arr[i+2]))

print(cal(0))

Measured memory_bytes: 266060
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

struct E{
	int s,x;
	bool operator<(const E& e)const{
		if(s!=e.s)return s<e.s;
		return x<e.x;
	}
};

vector<E> ss;
vector<E> ts;
map<int,int> ms;

int main() {
	// your code goes here
	int n,q;
	cin>>n>>q;
	for(int i=0;i<n;i++){
		int x;
		E e1;
		E e2;
		cin>>e1.s>>e2.s>>x;
		e1.s-=x;
		e2.s-=x;
		e2.x=e1.x=x;
		ss.push_back(e1);
		ts.push_back(e2);
	}
	sort(ss.begin(),ss.end());
	sort(ts.begin(),ts.end());
	int p1=0,p2=0,p3=0;
	int d;
	cin>>d;
	while(p3<q){
		while(p1<ss.size() && ss[p1].s<=d){
			ms[ss[p1].x]++;
			p1++;
		}
		while(p2<ts.size() && ts[p2].s<=d){
			ms[ts[p2].x]--;
			if(ms[ts[p2].x]<=0)ms.erase(ts[p2].x);
			p2++;
		}
		if(ms.size()==0){
				cout<<"-1\n";
		}else{
			map<int,int>::iterator it=ms.begin();
			cout<<(*it).first<<"\n";
		}
		cin>>d;
		p3++;
	}
	return 0;
}

Measured memory_bytes: 13796
import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val inputs = Iterator.continually(StdIn.readLine()).takeWhile(_ != null)
    for{
      in <- inputs
      val Array(h, w, _*) = in.split(" ").map(_.toInt)
      }{
        if(h != 0 && w != 0) println(List.tabulate(h, w) { (i, j) =>
          val simbol = if ((i % 2 == 0 && j % 2 == 0) ||
            (i % 2 != 0 && j % 2 != 0)) "#"
          else "."
          val EOS = if(j == w - 1) "\n" else ""
          simbol + EOS
        }.flatten.mkString)
      }
  }
}

Measured memory_bytes: 58872
#include<stdio.h>

static const int MAX = 500;
static const int INFTY = (1<<21);

int main(){
  int n,i,j,e,sum,u,v,min;
  int use[MAX],pi[MAX],key[MAX], M[MAX][MAX];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      M[i][j]=(e==-1)?INFTY:e;
    }
  }

  for(i=0;i<n;i++){
    key[i]=INFTY;
    pi[i]=-1;
  }

  key[0]=0;

  for(i=0;i<n;i++){
    use[i]=-1;
  }

  while(1){
    u=-1;
    min=INFTY;
    for(i=0;i<n;i++){
      if(key[i]<min && use[i]==-1){
	u=i;
	min=key[i];
      }
    }

    if(u==-1){
      break;
    }
    use[u]=1;
    for(v=0;v<n;v++){
      if(M[u][v]<key[v] && use[v]==-1){
	key[v]=M[u][v];
	pi[v]=u;
      }
    }
  }

  sum=0;

  for(i=0;i<n;i++){
    if(pi[i]!=-1)sum+=M[i][pi[i]];
  }

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

Measured memory_bytes: 804
if __name__ == "__main__":
    y, m, d = [int(i) for i in input().split(sep="/")]
    if y > 2019:
        print("TBD")
    elif y == 2019:
        if m >= 5:
            print("TBD")
        else:
            print("Heisei")
    else:
        print("Heisei")

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
        if(n%2==0 && a.at(i)%2==0){
            cout<<0<<endl;
            return 0;
        }
        else if(n%2==1 && a.at(i)%2==1){
            cout<<0<<endl;
            return 0;
        }
    }

    vector<int>b(n,-1);

    for(int i=0;i<n;i++){
        if(n%2==1){
            if(b.at(n/2-a.at(i)/2)==-1){
                b.at(n/2-a.at(i)/2)=1;
            }
            else if(b.at(n/2+a.at(i)/2)==-1){
                b.at(n/2+a.at(i)/2)=1;
            }
            else{
                cout<<0<<endl;
                return 0;
            }
        }
        else{
            if(b.at((n-1)/2-a.at(i)/2)==-1){
                b.at((n-1)/2-a.at(i)/2)=1;
            }
            else if(b.at((n/2+a.at(i)/2))==-1){
                b.at((n/2+a.at(i)/2))=1;
            }
            else{
                cout<<0<<endl;
                return 0;
            }
        }
    }

    sort(a.begin(),a.end());
    a.push_back(-1);
    ll ans=1;
    for(int i=0;i<n;i++){
        if(a.at(i)==a.at(i+1)){
            ans=ans*2%1000000007;
        }
    }
    cout<<ans<<endl;






    return 0;
}


Measured memory_bytes: 1408
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		if (B/A>=C) {
			System.out.println(C);
		}else {
			System.out.println(B/A);
		}
	}
}

Measured memory_bytes: 22996