akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second
#define NIL -1
using ll = long long;
const ll MOD = 1000000007;
#define REP(i,n) for (ll i=0; i < (n); ++i)
#define FOR(i,a,b) for (ll i=(a); i < (b); ++i)
using namespace std;

int get_gcd(int a, int b){while(1){if (a < b) swap(a, b); if (b == 0) return a; a %= b;}}
int get_lcm(int a, int b){return a * b / get_gcd(a, b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n,m;
  cin >> n >> m;

  vector<pair<int,int>> e(m);
  REP(i,m) {
    cin >> e[i].fi >> e[i].se;
    e[i].fi--;
    e[i].se--;
  }

  struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> size_; // iが根の場合の木のサイズ
    vector<int> rank_; // iが根の場合の木のランク

    UnionFind(int n) : par(n), size_(n, 1), rank_(n, 0) { //最初は全てが根であるとして初期化
        REP(i,n) par[i] = i;
    }

    int root(int& x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]); // 経路圧縮しつつ返却
    }

    void unite(pair<int,int>& a) { // xとyの木を併合
        int rx = root(a.fi); //xの根をrx
        int ry = root(a.se); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま

        //ランクが大きい方をryにしてそれを親とする。
        if (rank_[rx] > rank_[ry]) swap(rx, ry);
        if (rank_[rx] == rank_[ry]) rank_[ry]++;
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        size_[ry] += size_[rx];
        return;
    }

    bool same(pair<int,int>& a) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(a.fi);
        int ry = root(a.se);
        return rx == ry;
    }

    int size(int& x) { // xが属する木のサイズ
      return size_[root(x)];
    }
  } uf(n);

  vector<int> ans(m);
  ans[m-1] = n*(n-1)/2;
  for (int i=m-1; i>0; i--) {
    if (uf.same(e[i])) ans[i-1] = ans[i];
    else ans[i-1] = ans[i] - uf.size(e[i].fi) * uf.size(e[i].se);
    uf.unite(e[i]);
  }

  REP(i,m) cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 6016
def main
  str = ARGF.gets.chomp

  n = str.to_i
  digits = str.chars.map(&:to_i)

  s = 0
  digits.each do |d|
    s += d
  end

  if n % s == 0
    puts 'Yes'
  else
    puts 'No'
  end
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 3836
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define INF 1000000000000000000LL
using namespace std;

int main()
{
	int n, a[51], b[51];
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		scanf("%d", &a[i]);
	}
	for(int i=0; i<n; i++){
		scanf("%d", &b[i]);
		if(a[i]<b[i]){
			printf("%d\n", -1); 
			return 0;
		}
	}
	long long int p2[51];
	p2[0]=1;
	for(int i=1; i<=50; i++){
		p2[i]=p2[i-1]*2;
	}
	long long int d[51][51];
	for(int i=0; i<=50; i++){
		for(int j=0; j<=50; j++){
			if(i==j){
				d[i][j]=0;
			}else{
				d[i][j]=INF;
			}
		}
	}
	for(int i=1; i<=50; i++){
		for(int j=0; j<=i-1; j++){
			for(int k=j+1; k<=i-j; k++){
				if((i-j)%k==0){
					d[i][j]=p2[k];
					break;
				}
			}
		}
	}
	for(int k=0; k<=50; k++){
		for(int i=0; i<=50; i++){
			for(int j=0; j<=50; j++){
				if(d[i][j]>d[i][k]+d[k][j]) d[i][j]=d[i][k]+d[k][j];
			}
		}
	}

	long long int ans=0;
  set<int> s[50];
  for(int i=0; i<n; i++){
    s[i].insert(a[i]);
  }
  while(1){
    long long int dmax=0;
    int e=0;
    for(int i=0; i<n; i++){
      long long int min=INF;
      for(auto itr=s[i].begin(); itr!=s[i].end(); itr++){
        int x=*itr;
        if(min>d[x][b[i]]) min=d[x][b[i]];
      }
      if(min==INF){
        e=2;
        break;
      }
      if(dmax<min){
        dmax=min;
        e=1;
      }
    }
    if(e==0){
      break;
	}else if(e==2){
      printf("%d\n", -1);
      return 0;
    }
    int k;
	for(int i=0; i<=50; i++){
		if(dmax>=p2[i]) k=i;
	}
    ans=ans+p2[k];
    for(int i=0; i<n; i++){
      set<int> t;
      for(auto itr=s[i].begin(); itr!=s[i].end(); itr++){
        int x=*itr;
        t.insert(x%k);
      }
      for(auto itr=t.begin(); itr!=t.end(); itr++){
        s[i].insert(*itr);
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 384
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    ll A, B, C;
    cin >> A >> B >> C;
    cout << max<ll>(0, C - (A - B)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=false;

int main(){
    long long n,m;
    long long a[51],b[51],c[51],d[51];
    cin>>n>>m;
    rep(i,0,n)cin>>a[i]>>b[i];
    rep(i,0,m)cin>>c[i]>>d[i];
    
    for(int i=0;i<n;i++){
        long long z=INF,point;
        for(int j=0;j<m;j++){
            long long now=abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(z>now){
                z=now;
                point=j+1;
            }
        }
        cout<<point<<endl;
    }
    
    return 0;
}

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

int main() {
  int n;
  cin>>n;
  int m = 0;
  for (int i=0; i<n; i++) {
    int l, r;
    cin>>l>>r;
    m += r - l  + 1;
  }
  cout<<m<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    long long int a,b,g,l;
    while(cin>>a>>b)
    {
        long long int temp;
        if(a<b)
            {
                temp=a;
                a=b;
                b=temp;
            }
            g=gcd(a,b);
            l=a*b/g;
            cout<<g<<" "<<l<<endl;
    }
    return 0;
}

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

#define ll int64_t
using namespace std;
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){
   ll n,k;
   cin>>n>>k;
   vector<ll> p(n),q(n,0);

   fo(i,n) cin>>p[i];
   ll final=min((ll)52,k);
    fo(i,final){
        
        fo(j,n){
            ll a=max((ll)0,j-p[j]); ll b=min(n-1,j+p[j]);
            q[a]++;
           // if(i==final-1) dbg2(a,b);
            if(b!=n-1) q[b+1]--;
        }
        fo(j,n-1) q[j+1]=q[j+1]+q[j];
        p=q;
        fo(j,n) q[j]=0;
    }
    fo(i,n) cout<<p[i]<<" ";
    cout<<endl;
   
    

   
}


Measured memory_bytes: 6432
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5+2;
int arr[N],dp[N];
int n;



int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);


    
   	cin>>n;
   	for(int i=0;i<n;i++)
   		cin>>arr[i];

   	dp[0]=0;
   	if(n!=1)
   		dp[1]=abs(arr[0]-arr[1]);

   	for(int i=2;i<n;i++)
   		dp[i] = min( dp[i-1] + abs(arr[i]-arr[i-1]),  dp[i-2] +abs(arr[i] - arr[i-2]));

   	cout<<dp[n-1];

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define rg register
using namespace std;
ll K,A,B,Ans;
int main()
{   scanf("%lld%lld%lld",&K,&A,&B);
	if(A+2<B)
	{   if(K<=A-1) return printf("%lld\n",K+1),0;
		K-=A-1,Ans=A,Ans+=(K/2)*(B-A)+K%2,printf("%lld\n",Ans);
	}
	else printf("%lld\n",K+1);
}


Measured memory_bytes: 256
path = list(input())
if ('N' in path) is True:
    north = 1
else:
    north = 0
if ('S' in path) is True:
    south = -1
else:
    south = 0
if ('E' in path) is True:
    east = 1
else:
    east = 0
if ('W' in path) is True:
    west = -1
else:
    west = 0
if ((north + south) == 0) and ((east + west) == 0):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

ll ketasu(ll a){
   ll num=1;
   while(a/10){
       num++;
       a/=10;
   }
   return num;
}

ll gcd(ll a,ll b){return b ? gcd(b,a%b) :a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

ll kosuu(ll a){
    ll sum=0;
    for(ll i=1;i*i<=a;i++){
        if(a%i==0){
            if(a!=1&&i*i!=a){
            sum+=2;
            }else{
             sum++;   
            }
        }
    }
    return sum;
}
ll M=1000005;

int main()
{
ll n;
cin>>n;
vector<ll>cnt(M);
vector<ll>s(n);
rep(i,n){
    cin>>s[i];
}
for(ll x:s){
  if(cnt[x]!=0){
      cnt[x]=2;
      continue;
  }
  for(ll i=x;i<M;i+=x)cnt[i]++;
}

ll ans=0;
for(ll x:s){
    if(cnt[x]==1)ans++;
}
cout<<ans<<endl;
}



Measured memory_bytes: 12688
#include<iostream>
using namespace std;
#define df 0

int main(){
  if(df) printf("*debug mode*\n");
  int n; cin >> n;
  int M=0,temp,cnt=0; cin >> temp;
  for(int i=0;i<n-1;i++){
    int a; cin >> a;
    if(temp<a){
      M=max(M,cnt);
      cnt=0;
    }
    else cnt++;
    temp=a;
  }
  if(cnt>M)M=cnt;
  cout << M;
}

/// confirm df==0 ///


Measured memory_bytes: 256
import java.util.stream.*;
class Main {
  public static void main(String[] args) {
    IntStream.rangeClosed(1, 9)
      .forEach(i -> IntStream.rangeClosed(1, 9)
                      .forEach(j -> System.out.println(i + "x" + j + "=" + i * j))
      );
  }
}

Measured memory_bytes: 30464
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int[][] m = new int[3][3];
    String result = "";
    
    for(int i = 0 ; i < 3 ; ++i){
      for(int j = 0 ; j < 3 ; ++j){
        m[i][j] = sc.nextInt();
      }
    }
    //縦比較
    int a = m[0][0] - m[0][1];//1
    int b = m[0][0] - m[0][2];//2
    int c = m[1][0] - m[1][1];//1
    int d = m[1][0] - m[1][2];//2
    int e = m[2][0] - m[2][1];//1
    int f = m[2][0] - m[2][2];//2
    //横比較
    int g = m[0][0] - m[1][0];//1
    int h = m[0][0] - m[2][0];//2
    int i = m[0][1] - m[1][1];//1
    int j = m[0][1] - m[2][1];//2
    int k = m[0][2] - m[1][2];//1
    int l = m[0][2] - m[2][2];//2
    
    //比較する
    boolean ac = a==c;
    boolean ae = a==e;
    boolean ce = c==e;
    boolean ace = ac&&ae&&ce;
    boolean bd = b==d;
    boolean bf = b==f;
    boolean df = d==f;
    boolean bdf = bd&&bf&&df;
    boolean gi = g==i;
    boolean gk = g==k;
    boolean ik = i==k;
    boolean gik = gi&&gk&&ik;
    boolean hj = h==j;
    boolean hl = h==l;
    boolean jl = j==l;
    boolean hjl = hj&&hl&&jl;
    
    if(ace && bdf && gik && hjl){
      result = "Yes";
    }else{
      result = "No";
    }

    System.out.println(result);
    
  }
}



Measured memory_bytes: 35744
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

int main() {
  string s;
  while (cin >> s) {
    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) cout << "Bad" << endl;
    else cout << "Good" << endl;
  }
}


Measured memory_bytes: 888
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

void A_500_Yen_Coins(void) {

	int K, X;
	cin >> K >> X;
	cout << ((500 * K >= X) ? "Yes" : "No") << flush;
	return;
}

void B_Count_ABC(void) {

	int N;
	string S;
	cin >> N >> S;

	int counter = 0;
	for (int loop = 0; loop < N - 2; loop++) {
		if (S[loop] == 'A' && S[loop + 1] == 'B' && S[loop + 2] == 'C') counter++;
	}
		
	cout << counter << flush;
	return;
}

void C_Count_Order(void) {

	int N;
	cin >> N;
	vector<int> P(N);
	for (int& it : P) cin >> it;
	vector<int> Q(N);
	for (int& it : Q) cin >> it;

	vector<int> sample(N);
	int index = 0;
	int a = 0;
	int b = 0;
	for (int loop = 0; loop < N; loop++) sample[loop] = loop + 1;
	do {
		if (P == sample) a = index;
		if (Q == sample) b = index;
		index++;
	} while (next_permutation(sample.begin(), sample.end()));

	cout << abs(a - b) << flush;
	return;
}

void D_Semi_Common_Multiple(void) {

	int N, M;
	cin >> N >> M;
	vector<int> a(N);
	for (int& it : a) {
		cin >> it;
		it /= 2;
	}
	sort(a.begin(), a.end());
	
	int Xmin = 0;
	for (int X = a[N - 1]; X <= M; X += a[N - 1]) {
		for (int& it : a) {
			if (!(X % it == 0 && X / it % 2 == 1)) goto nextSample;
		}
		Xmin = X;
		break;
	nextSample:
		continue;
	}

	cout << ((Xmin == 0) ? 0 : int((M + Xmin) / (Xmin * 2))) << flush;
	return;
}

int main(void) {

	//A_500_Yen_Coins();
	//B_Count_ABC();
	//C_Count_Order();
	D_Semi_Common_Multiple();
	return 0;
}


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

int main(int argc, char const *argv[]) {
  int k;scanf("%d", &k);
  int ans = 0;
  vector<int> num(k+1, 0);
  for(int i=k;i>0;i--){
    num[i] += (k/i)*(k/i)*(k/i);
    for(int j=2;j*j<=i;j++){
      if(i%j!=0) continue;
      num[j] -= num[i];
      if(j*j!=i) num[i/j] -= num[i];
    }
    if(i!=1) num[1] -= num[i];
    ans += num[i] * i;
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 3228
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#define MOD 1000000007
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
int par[114514];//親
int urank[114514];//深さ
int cnt[114514];
//n要素で初期化
void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        urank[i]=0;
        cnt[i]=1;
    }
    return;
}

//木の根を求める
int find(int x){
    if(par[x]==x){
        return x;
    }else{
        return par[x]=find(par[x]);
    }
}

//xとyの属する集合を併合
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;
    
    if(urank[x]<urank[y]){
        par[x]=y;
        cnt[y]+=cnt[x];
    }else{
        par[y]=x;
        cnt[x]+=cnt[y];
        if(urank[x]==urank[y])urank[x]++;
    }
    return;
}

//xとyが同じ集合に属するか否か
bool same(int x,int y){
    return find(x)==find(y);
}

signed main(){
    int n,m;
    cin>>n>>m;
    vector<pair<int,int>> b;
    for(int i=0;i<m;i++){
        int f,s;
        cin>>f>>s;
        b.push_back(make_pair(f-1,s-1));
    }
    reverse(begin(b),end(b));
    int ans=0;
    vector<int> out;
    out.push_back(n*(n-1)/2);
    init(n);
    for(int i=0;i<m-1;i++){
        if(find(b[i].first)!=find(b[i].second)){
            ans+=cnt[find(b[i].first)]*cnt[find(b[i].second)];
        }
        unite(b[i].first,b[i].second);
        out.push_back(n*(n-1)/2-ans);
    }
    reverse(begin(out), end(out));
    for(int i=0;i<out.size();i++)cout<<out[i]<<endl;
    return 0;
}


Measured memory_bytes: 7024
#include<bits/stdc++.h>
const long long mod = 1000000007;


int main()
{
    int n,d,a;
    std::cin >> n >> d >> a;
    std::vector<long long> x(n),h(n);
    for(int i = 0; i < n; i++)std::cin >> x[i] >> h[i];
    std::vector<int> ids(n);
    for(int i = 0; i < n; i++)ids[i] = i;
    std::sort(ids.begin(),ids.end(),[&](int i, int j){return x[i] < x[j];});
    std::vector<long long> nx(n),nh(n);
    for(int i = 0; i < n; i++)nx[i] = x[ids[i]], nh[i] = h[ids[i]];
    x = nx, h = nh;

    std::vector<long long > s(n + 1, 0);
    long long res = 0;
    for(int i = 0; i < n; i++){
        if(s[i] < h[i]){
            long long need = (h[i] - s[i] + a - 1) / a;
            long long right = x[i] + d * 2;
            int id = std::upper_bound(x.begin(),x.end(),right) - x.begin();

            s[i] += need * a;
            s[id] -= need * a;
            res += need;
        }
        s[i + 1] += s[i];
    }
    std::cout << res << std::endl;
}

Measured memory_bytes: 8832
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

// type alias
using ll = long long;
using ull = unsigned long long;

inline bool isPower2(ull a)
{
	if (a == 0)
	{
		return false;
	}
	return !(a & (a - 1));
}

inline ll getMaxEffectiveBit(ull a)
{
	ll index = -1;
	for (; a != 0; a >>= 1)
	{
		++index;
	}
	return index;
}

inline ll getSpecifiedBit(ull a, unsigned bit)
{
	return (a & (1LL << bit)) >> bit;
}

// computational complexity: o(log(max(a, b))) 
inline ull getGcd(ull a, ull b)
{
	if (b == 0)
	{
		return a;
	}
	return getGcd(b, a % b);
}

template<class Integer>
inline Integer getPower(Integer base, unsigned exponential)
{
	Integer res = 1;
	while (exponential >= 1)
	{
		if (exponential & 1)
		{
			res *= base;
		}
		base = base * base;
		exponential >>= 1;
	}

	return res;
}

template<class Integer>
class BinaryIndexedTree
{
private:
	ull maxSize_;
	vector<Integer> values_;
public:
	BinaryIndexedTree(ull maxSize) : maxSize_(maxSize), values_(maxSize_, 0) {}

	void update(ll index, Integer increment)
	{
		if (maxSize_ <= index)
		{
			throw invalid_argument("Index should be less than maxSize.");
		}
		++index;

		while (index <= maxSize_)
		{
			values_[index - 1] += increment;
			index += index & -index;
		}
	}

	Integer query(ll index)
	{
		if (maxSize_ <= index)
		{
			throw invalid_argument("Index should be less than maxSize.");
		}
		++index;

		Integer res = 0;
		while (index > 0)
		{
			res += values_[index - 1];
			index -= index & -index;
		}
		return res;
	}
};
using bitll = BinaryIndexedTree<ll>;



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

	vector<ll> burgerSheaf(51);
	vector<ll> burgerPatty(51);

	burgerSheaf[0] = 1;
	burgerPatty[0] = 1;
	for (ll i = 1; i <= 50; ++i)
	{
		burgerSheaf[i] = burgerSheaf[i - 1] * 2 + 3;
		burgerPatty[i] = burgerPatty[i - 1] * 2 + 1;
	}

	ll N, X;
	cin >> N >> X;

	ll res = 0;
	while (N > 0 && X > 0)
	{
		--X;
		--N;
		if (X >= burgerSheaf[N])
		{
			X -= burgerSheaf[N];
			res += burgerPatty[N];
			if (X == 0)
			{
				break;
			}
			--X;
			++res;
			if (X >= burgerSheaf[N])
			{
				res += burgerPatty[N];
				break;
			}
		}
	}

	cout << res << endl;

	return 0;
}


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

using namespace std;

main() {
    string s;
    cin >> s;
    int n = s.size();
    int ans = n;
    for (int i = 0; i < n - 1; ++i) {
        if (s[i] == s[i + 1]) {
            if (i + 2 == n) {
                ans--;
                i++;
            } else {
                ans--;
                i += 2;
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	int x[101],y[101],h[101];
	scan(N);
	rep(i,N){
		scan(x[i]);scan(y[i]);scan(h[i]);
	}
	int Cx,Cy,H;
	rep(cx,101){
		rep(cy,101){
			int flag=1;
			int nonzeroh=0;
			rep(i,N){
				if(h[i]!=0){
					nonzeroh=i;
					break;
				}
			}
			int kariH=h[nonzeroh]+abs(x[nonzeroh]-cx)+abs(y[nonzeroh]-cy);
			rep(i,N){
				if(max(0,kariH-abs(x[i]-cx)-abs(y[i]-cy))!=h[i]){
					flag=0;
					break;
				}
			}
			if(flag){
				Cx=cx,Cy=cy,H=kariH;
				printf("%d %d %d\n",Cx,Cy,H);
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
#include <chrono>

#define _ << " " <<
#define all(v) v.begin(), v.end()
#define sp(n) fixed << setprecision(n)
#define ff first
#define ss second

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 1e9 + 7;
const double eps = DBL_EPSILON;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef LOCAL_DEBUG
	freopen("input.txt", "r", stdin);
#endif
	int h, a;
	cin >> h >> a;
	cout << h / a + (h % a != 0);
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
using namespace std;
typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e18;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

int main(){
    ll N, M, X, Y; cin >> N >> M >> X >> Y;
    vl xs(N, 0), ys(M,0); REP(i, N) cin >> xs[i]; REP(i, M) cin >> ys[i];
    sort(xs.begin(), xs.end());
    sort(ys.begin(), ys.end());
    bool ok = true;
    ll xr = xs[xs.size()-1], yl = ys[0];
    ok = ok && (xr <= yl);
    if(ok){
        bool tmp = false;
        FOR(i, xr+1, yl+1){
            if(X < i && i <= Y){
                tmp = true; break;
            }
        }
        ok = tmp;
    }
     cout << (ok ? "No War" : "War") << endstr;
    return 0;
}


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


int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> dp(n), a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  dp[0] = 0;
  for (int i = 1; i < n; ++i) {
    for (int j = 1; j <= i and j <= k ; ++j) {
      if (j == 1)
        dp[i] = dp[i-1] + abs(a[i] - a[i-1]);
      else
        dp[i] = min(dp[i], dp[i-j] + abs(a[i] - a[i-j]));
    }
  }
  cout << dp[n-1] << '\n';

  return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), x = sc.nextInt();
		int a[] = new int[n];
		for (int i = 0; i < n; ++i)
			a[i] = sc.nextInt();
		sc.close();
		long ans = 0;
		int tmp = a[0];
		if(tmp > x){
			ans = (long)(tmp - x);
			a[0] = x;
		}
		for(int i = 1; i < n; ++i){
			tmp = a[i] + a[i - 1];
			if(tmp > x){
				ans += (long)(tmp - x);
				a[i] -= tmp - x;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 51876
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n,q=gsmi
ar=Array.new(n){[]}
#ans=[]
q.times do
  inp=gsmi
  case inp[0]
  when 0
    ar[inp[1]]<<inp[2]
  when 1
    #ans<<ar[inp[1]]
    puts ar[inp[1]].join(" ")
  when 2
    ar[inp[1]]=[]
  end
end
#ans.each{|i|puts i.join(" ")}


Measured memory_bytes: 15740
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL a,b,num,ans=1;
map <LL,LL> aa,bb;

int main()
{
	cin>>a>>b;
	for(LL i=2;i*i<=a;i++)
	{
		num=0;
		while(a%i==0)
		{
			a/=i;
			num++;
		}
		if(num>0) aa[i]++;
	}
	if(a>1) aa[a]++;
	for(LL i=2;i*i<=b;i++)
	{
		num=0;
		while(b%i==0)
		{
			b/=i;
			num++;
		}
		if(num>0) bb[i]++;
	}
	if(b>1) bb[b]++;
	for(map <LL,LL>::iterator it=aa.begin();it!=aa.end();it++) if(bb[it->fi]>0) ans++;
	cout<<ans<<endl;
	return 0;
}

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

def cmb(n, r, mod):
	a = 1
	b = 1
	r = min(r, n-r)
	for i in range(r):
		a = a * (n-i) % mod
		b = b * (i+1) % mod
	return a * pow(b, mod-2, mod) % mod

def main():
    n, a, b = map(int, input().split())
    MOD = 10**9+7
    total = pow(2, n, MOD)
    a_ = cmb(n, a, MOD)
    b_ = cmb(n, b, MOD)

    print((total - a_ - b_ - 1) % MOD)

main()

Measured memory_bytes: 3064
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
    ll n, k;
    cin >> n >> k;
    ll ans = 1;
    for(int i = 0; i < n; ++i){
        if(ans < k){
            ans *= 2;
        }else{
            ans += k;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 888
from collections import Counter
import sys

readline = sys.stdin.readline
n = int(readline())
a = tuple(map(int, readline().split()))

counter = Counter(a)
c = [0] * n
for k, v in counter.items():
    c[k-1] = v


def comb(n):
    r = 2
    numerator = denominator = 1
    for i in range(r):
        numerator = numerator * (n - i)
        denominator = denominator * (i + 1)
    return numerator // denominator


combination = tuple(map(comb, c))
comb_sum = sum(combination)
for i in a:
    i -= 1
    if c[i] > 0:
        print(comb_sum - (c[i] - 1))
    else:
        print(comb_sum)


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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  string s, t;
  cin >> s >> t;

  int ans = INF;
  for (int i = 0; i <= s.size() - t.size(); i++) {
    string tmp = s.substr(i, t.size());
    int cnt = 0;
    for (int j = 0; j < t.size(); j++) {
      if (t[j] != tmp[j]) cnt++;
    }
    ans = min(ans, cnt);
  }

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


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


using namespace std;

int main()
{long long int A,B;
cin>>A>>B;
if(A>=13){
    cout<<B<<endl;
}if(A<13&&A>5){
    cout<<B/2<<endl;
}if(A<=5){
    cout<<0<<endl;
}
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

            int c1 = 0, c2 = 0, c3 = 0;
            for (int i = 0; i < N; i++) {
                int a = sc.nextInt();

                if (a == 1) {
                    c1++;
                } else if (a == 2) {
                    c2++;
                } else if (a == 3) {
                    c3++;
                }
            }

            double[][][] dp = new double[c1 + c2 + c3 + 1][c2 + c3 + 1][c3 + 1];

            double ans = solve(N, dp, c1, c2, c3);

            System.out.println(ans);
        }
    }

    static double solve(int N, double[][][] dp, int c1, int c2, int c3) {
        if (dp[c1][c2][c3] != 0) {
            return dp[c1][c2][c3];
        }

        int c = c1 + c2 + c3;

        if (c == 0) {
            return 0;
        }

        dp[c1][c2][c3] = (double) N / c;

        if (c1 > 0) {
            dp[c1][c2][c3] += solve(N, dp, c1 - 1, c2, c3) * c1 / c;
        }

        if (c2 > 0) {
            dp[c1][c2][c3] += solve(N, dp, c1 + 1, c2 - 1, c3) * c2 / c;
        }

        if (c3 > 0) {
            dp[c1][c2][c3] += solve(N, dp, c1, c2 + 1, c3 - 1) * c3 / c;
        }

        return dp[c1][c2][c3];
    }

}


Measured memory_bytes: 307152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    string S;
    cin >> N >> S;
    string T=S.substr(0,N/2);
    if(S==T+T) cout << "Yes" << endl;
    else cout << "No" << endl;



}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>
 
using namespace std;
 
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>
 
typedef vector<int> vec;
typedef vector<vec> mat;
 
const ll mod = 1000000007;
 
int main(){
    int a, b;
    cin >> a >> b;
    int ans = 0;
    int n = 1;
    while(n < b){
        n += a - 1;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
import sys

N = int(sys.stdin.readline())
B = list(map(int, sys.stdin.readline().split()))

ans = []
while B:
    for i in range(N-1, -1, -1):
        if B[i] == i + 1:
            ans.append(B[i])
            B.pop(i)
            N -= 1
            break
    else:
        break

if B:
    print(-1)
else:
    for a in ans[::-1]:
        print(a)

Measured memory_bytes: 9192
#include<bits/stdc++.h>
#define ll long long
#define fast ios::sync_with_stdio(false); cin.tie(0);
#define f(i,s,e) for(ll i=s;i<e;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define mod 1000000007
#define all(x) x.begin(),x.end()
using namespace std;
double dp[3000][3000],arr[3000],ans;

int main(){
    fast;

    int n;
    cin>>n;

    for(int i=1;i<=n;i++)
        cin>>arr[i];

    dp[1][0]=1-arr[1];
    dp[1][1]=arr[1];
    for(int i=2;i<=n;i++)
        dp[1][i]=0;

    for(int i=2;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(j==0)
                dp[i][0] = dp[i-1][0]*(1 - arr[i]);
            else
                dp[i][j] = dp[i-1][j]*(1-arr[i]) + dp[i-1][j-1]*arr[i];
        }
    }

    for(int i=(n/2)+1;i<=n;i++)
        ans+=dp[n][i];

    printf("%.15lf",ans);

}


Measured memory_bytes: 70528
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL n;
    LL c;
    cin >> n >> c;
    vector<vector<LL>> d(c,vector<LL>(c));
    for(LL i=0; i<c; i++){
        for(LL j=0; j<c; j++){
            cin >> d[i][j];
        }
    }
    vector<vector<LL>> c_div(3);
    vector<vector<pair<LL,LL>>> c_sum(3, vector<pair<LL,LL>>(c));
    LL tmp;
    LL tmp_div;
    for(LL i=0; i<n; i++){
        for(LL j=0; j<n; j++){
            tmp_div=(i+j)%3;
            cin >> tmp;
            tmp--;
            c_div[tmp_div].push_back(tmp);
        }
    }
    for(LL i=0; i<3; i++){
        for(LL j=0; j<c; j++){
            c_sum[i][j].first=0;
            c_sum[i][j].second=j;
            for(LL k=0; k<c_div[i].size(); k++){
                c_sum[i][j].first+=d[c_div[i][k]][j];
            }
        }
    }

    sort(c_sum[0].begin(),c_sum[0].end());
    sort(c_sum[1].begin(),c_sum[1].end());
    sort(c_sum[2].begin(),c_sum[2].end());
    LL c_max=NIL;
    LL tmp_sum;
    for(LL i=0; i<3; i++){
        for(LL j=0; j<3; j++){
            for(LL k=0; k<3; k++){
                if(c_sum[0][i].second==c_sum[1][j].second || c_sum[0][i].second==c_sum[2][k].second || c_sum[1][j].second==c_sum[2][k].second){
                    continue;
                }
                tmp_sum=c_sum[0][i].first+c_sum[1][j].first+c_sum[2][k].first;
                if(c_max==NIL){
                    c_max=tmp_sum;
                }else{
                    c_max=min(c_max,tmp_sum);
                }
            }
        }
    }

    cout << c_max << endl;

    return 0;
}


Measured memory_bytes: 5396
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <fstream>
#include <sstream>
#include <queue>
#include <exception>
#include <cmath>
#include <numeric>
#include <map>
#include <algorithm>
#include <bitset>
#include <set>
#include <functional>

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;
typedef long long int lint;

void init(int* c) {
	REP(i, 10) {
		c[i] = 0;
	}
}

int cy[9] = { 1, 1, 1, 4, 4, 4, 7, 7, 7 };
int cx[9] = { 1, 4, 7, 1, 4, 7, 1, 4, 7 };
int dy[9] = { -1, -1, -1, 0, 0, 0, 1, 1, 1 };
int dx[9] = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };

void check(int n) {

	int puz[9][9] = { 0 };
	bool err[9][9] = { 0 };

	REP(i, 9) {
		REP(j, 9) {
			cin >> puz[i][j];
		}
	}

	int* count = new int[10];
	//???????????£???
	REP(i, 9) {
		init(count);
		REP(j, 9) {
			count[puz[i][j]]++;
		}
		FOR(num, 1, 10) {
			if (count[num] > 1) {
				REP(j, 9) {
					if (puz[i][j] == num) err[i][j] = true;
				}
			}
		}
	}
	//???????????£???
	REP(j, 9) {
		init(count);
		REP(i, 9) {
			count[puz[i][j]]++;
		}
		FOR(num, 1, 10) {
			if (count[num] > 1) {
				REP(i, 9) {
					if (puz[i][j] == num) err[i][j] = true;
				}
			}
		}
	}
	//????????????????????£???
	REP(i, 9) {
		init(count);
		REP(j, 9) {
			count[puz[cy[i] + dy[j]][cx[i] + dx[j]]]++;
		}
		FOR(num, 1, 10) {
			if (count[num] > 1) {
				REP(j, 9) {
					if (puz[cy[i] + dy[j]][cx[i] + dx[j]] == num) err[cy[i] + dy[j]][cx[i] + dx[j]] = true;
				}
			}
		}
	}

	if (n != 0) cout << endl;
	REP(i, 9) {
		REP(j, 9) {
			cout << (err[i][j] ? '*' : ' ') << puz[i][j];
		}
		cout << endl;
	}
	
	delete[] count;
}

bool AOJ0124()
{
	int n;
	cin >> n;

	REP(i, n) {
		check(i);
	}

	return true;
}

int main()
{
	AOJ0124();

	return 0;
}

Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef vector<int> VI;
typedef vector<ll> VLL;

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

    sort(l.begin(),l.end());

    for(ll i=0; i<n-2; ++i){
        for(ll j=n-1; j>i+1; --j){
            if(l[j]-l[j-1] >= l[i])continue;
            
            for(ll k=i+1; k<j; ++k){
                if(l[j] - l[k] < l[i]){
                    ans ++;
                }
            }
            
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int N; cin >> N;
    string S; cin >> S;
    int a = 0;
    int b = S.size() - 1;

    int ans = 0;
    while(a < S.size() && b >= 0){
        while(S[a] == 'R' && a < S.size()) ++a;
        while(S[b] == 'W' && b >= 0) --b;
        if(a < b){
            ++ans;
            ++a;
            --b;
        }else{
            break;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3712
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int mod = (int)1e9 + 7;
int fact(int x) {
    int f = 1;
    for (int i = 1; i <= x; i++) {
        f = (1LL * f * i) % mod;
    }
    return f;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    int n, m;
    cin >> n >> m;
    if (abs(n - m) > 1) {
        cout << 0;
        return 0;
    }
    int p = fact(n);
    int r = fact(m);
    if (n == m) {
        p = (p + p) % mod;
    }
    cout << (1LL * p * r) % mod;
    return 0;
}

Measured memory_bytes: 256
using System;

class program
{
    static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        double a = double.Parse(str[0]);
        double b = double.Parse(str[1]);

        var area = a * b; //??¢???
        var length = (a * 2) + (b * 2); //??¨?????????

        Console.WriteLine("{0} {1}", area, length);
    }
}

Measured memory_bytes: 9220
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] A = new int[M];
    for(int n = 0; n < M; n++) {
        A[n] = sc.nextInt();
        N = N - A[n];
    }

    if(N >= 0) {
      System.out.println(N);
    } else {
      System.out.println("-1");
    }
  }
}

Measured memory_bytes: 46216
#include<bits/stdc++.h>
struct pos{
	int x,y;
	bool operator<(pos w)const{return x<w.x;}
}ps[200007];
int as[200007],ap=0;
int main(){
	int x1,y1,x2,y2,x,y,n,xs=1,ys=1,pp=0;
	scanf("%d%d",&x1,&y1);
	scanf("%d%d",&x2,&y2);
	if(x1>x2)xs=-1,x1*=-1,x2*=-1;
	if(y1>y2)ys=-1,y1*=-1,y2*=-1;
	scanf("%d",&n);
	for(int i=0;i<n;++i){
		scanf("%d%d",&x,&y);
		x*=xs,y*=ys;
		if(x<x1||x2<x||y<y1||y2<y)continue;
		ps[pp++]=(pos){x,y};
	}
	std::sort(ps,ps+pp);
//	if(x1==x2||y1==y2){
//		if(pp)printf("%.15f",(y2-y1+x2-x1)*100.-20+10*acos(-1));
//		else printf("%.15f",(y2-y1+x2-x1)*100.);
//		return 0;
//	}
	for(int i=0;i<pp;++i){
		int v=ps[i].y;
		if(!ap||v>as[ap])as[++ap]=v;
		else *std::lower_bound(as+1,as+ap+1,v)=v;
	}
	double val=0;
	if(std::min(y2-y1,x2-x1)+1==ap){
		val+=10*acos(-1)-20;
		--ap;
	}
	val+=(y2-y1+x2-x1)*100.-(20-acos(-1)*5)*ap;
	printf("%.15f",val);
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <numeric>
#include <utility>
#include <iomanip>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
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;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

int main() {
    int n;
    cin >> n;
    int cnt = 0;
    bool ans = false;
    for (int i=0; i<n; i++) {
        int d1, d2;
        cin >> d1 >> d2;
        if (d1 == d2) cnt++;
        else cnt = 0;
        if (cnt >= 3) ans = true;
    }
    cout << (ans?"Yes":"No") << endl;
}


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

using namespace std;

int main() {
    int N;
    cin >> N;

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

    sort(A, A + N, greater<int>());

    long long W = -1, H = -1;
    int before = A[0];
    for(int i = 1; i < N && H == -1; i++) {
        if(before == A[i]) {
            if(W == -1) {
                W = A[i];
            } else {
                H = A[i];
            }
            if(i < N) {
                i++;
            }
        }
        before = A[i];
    }

    if(W != -1 && H != -1) {
        long long ans = W * H;
        cout << ans << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10 ** 6)

inf = 10 ** 4


def larger(x, y):
    lx, ly = len(x), len(y)
    if lx > ly:
        return x
    elif lx < ly:
        return y
    else:
        x.sort(reverse=True)
        y.sort(reverse=True)
        for xx, yy in zip(x, y):
            if xx > yy:
                return x
            elif xx < yy:
                return y
        return x


def dfs(rest):
    if memo[rest] is not None:
        return memo[rest]

    res = []
    for use, number in d.items():
        if rest - use >= 0 and dp[rest - use] == dp[rest] - 1:
            res = larger(res, [number] + dfs(rest - use))

    memo[rest] = res
    return res


n, m = map(int, input().split())
a = tuple(map(int, input().split()))

needs = [inf, 2, 5, 5, 4, 5, 6, 3, 7, 6]
# needs[i] : 数字iを作るのに必要なマッチの本数

for i in range(1, 10):
    if i not in a:
        needs[i] = inf

d = {needs[i]: i for i in range(1, 10) if needs[i] != inf}
# d[本数] = その本数で作れる最大の数値

dp = [-inf] * (n + 1)
dp[0] = 0
# dp[j] : j本から構成できる桁数の最大値

for j in range(2, n + 1):
    for use, number in d.items():
        if j - use >= 0:
            dp[j] = max(dp[j], dp[j - use] + 1)

# print(dp)

memo = [None] * (n + 1)

ans = dfs(n)
ans.sort(reverse=True)
print(*ans, sep='')

Measured memory_bytes: 197340
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const ll N = 1e18;
int main() {
    fast_cin();
    ll n,c;
    cin>>n>>c;
     vector<ll> dp(c+1);//dp[i] - the maximum total value of items with total weight exactly i
    for(ll item=0;item<n;++item) {
        ll weight,value;
        cin>>weight>>value;
        for( ll weight_already=c-weight;weight_already>=0;--weight_already) {
                dp[weight_already+weight]=max(dp[weight_already+weight],dp[weight_already]+value);
        }
    }
    ll answer=0;
    for(int i=0;i<=c;i++) {
        answer=max(answer,dp[i]);
    }
    cout<<answer<<'\n';
}    

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

const ll MOD = 1000000007;
const ll MAX = 200100;
const double PI = 3.1415926;

#define vll vector<ll>
#define max_heap priority_queue<int>
#define min_heap priority_queue<int , vector<int>, greater<int> >
#define pb push_back
#define all(container) container.begin(), container.end()
#define pll pair<ll,ll>
#define printArr(name,from,to) for(int x = from; x < to; x++) cout << name[x] << " ";
// #define traverse( container, it) for( typeof(container.begin()) it = container.begin(); it!=container.end(); it++)
ll n;
ll h[MAX];
ll a[MAX];
ll fans[MAX];

ll seg[4*MAX];

void build(ll arr[], ll v, ll L, ll R)
{
	if (L == R)
		seg[v] = arr[L];
	else
	{
		ll mid = (L+R)/2;
		build(arr, 2*v, L, mid);
		build(arr, 2*v + 1, mid + 1, R);
		seg[v] = max(seg[2*v], seg[2*v + 1]);
	}
}

void update(ll v, ll L, ll R, ll x, ll y)
{
	if (L <= x && x <= R)
	{
		if (L == R)
			seg[v] += y;
		else
		{
			ll mid = (L+R)/2;
			update(2*v, L, mid, x, y);
			update(2*v + 1, mid + 1, R, x, y);
			seg[v] = max(seg[2*v], seg[2*v + 1]);
		}
	}
}

ll query(ll v, ll L, ll R, ll x, ll y)
{
	if (y < L || x > R)
		return 0;
	else if (x <= L && R <= y)
		return seg[v];
	else
	{
		ll mid = (L+R)/2;
		return max(query(2*v,L,mid,x,y), query(2*v + 1,mid+1,R,x,y));
	}
}

void print(ll v,ll L, ll R)
{
	if (L == R)
		cout << "L " << L << " R " << R << " " << seg[v] << endl;
	else
	{
		ll mid = (L+R)/2;
		print(2*v,L,mid);
		print(2*v+1,mid+1,R);
		cout << "L " << L << " R " << R << " " << seg[v] << endl;
	}
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	memset(seg,0,sizeof(seg));
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> h[i];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 0; i < n; i++)
	{
		ll temp = query(1,1,n,1,h[i]);
		update(1,1,n,h[i],a[i]+temp);
	}
	cout << seg[1] << endl;
	return 0;
}


Measured memory_bytes: 11264