akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
N = int(input())
xyh = [list(map(int,input().split())) for _ in range(N)]
h = 0
for i in xyh:
  if i[2] > h:
    x, y, h = i[0], i[1], i[2]
CXY = [[i,j] for i in range(0,100+1) for j in range(0,100+1)]
for cxy in CXY:
  ans=True
  H = h + abs(x - cxy[0]) + abs(y - cxy[1])
  for i in xyh:
    if max( H - abs(i[0] - cxy[0]) - abs(i[1] - cxy[1]) ,0) != i[2]:
      ans = False
  if ans:
    print(cxy[0],cxy[1],H)

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

int main() {
    //input
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    if(n <= k){
        cout << n * x << endl;
    }else{
        cout << k * x + (n-k) * y;
    }


    return 0;
}

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

int main() {
    double n, d, x, y;
    long int c = 0;
    cin>>n>>d;
    while(n--)
    {
        cin>>x>>y;
        if(sqrt(x*x+y*y) <= d)
            c++;
    }
    cout<<c;
    return 0;
}

Measured memory_bytes: 3800
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#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(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
typedef pair<LL,LL> LP;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int n;
	LL t;
	while(cin >> n >> t) {
		vector<LL> a(n);
		REP(i,n) cin >> a[i];
		LL ama = a[n-1];
		int amai = n-1;
		LL ma = 0;
		set<int> s;
		RREP(i,n){
			if(chmax(ama,a[i])){
				amai = i;
			}
			ma = max(a[amai]-a[i],ma);
		}
		DEBUG(ma);
		int ans = 0;
		ama = a[n-1];
		amai = n-1;
		RREP(i,n){
			if(chmax(ama,a[i])){
				amai = i;
			}
			if(ma == a[amai]-a[i]){
				DEBUG(a[i]); DEBUG(a[amai]);
				if(!s.count(amai)){
					ans++;
					s.insert(amai);
				}else{
					ans++;
					s.insert(i);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3328
n,x=map(int,input().split())

pb=[[0]*2 for i in range(n+1)]
pb[0][0]=1
pb[0][1]=1
for i in range(1,n+1):
    pb[i][0]=3+pb[i-1][0]*2
    pb[i][1]=1+pb[i-1][1]*2

def pbx(xx,nn):
#    print(xx,nn)
    if nn==0:
        return 1
    if xx==1:
        return 0
    elif xx<=1+pb[nn-1][0]:
        return pbx(xx-1,nn-1)
    elif xx==2+pb[nn-1][0]:
        return pb[nn-1][1]+1
    elif xx<=2+pb[nn-1][0]*2:
        xxx=pbx(xx-pb[nn-1][0]-2,nn-1)
#        print("xxx1",xxx)
        xxx=pb[nn-1][1]+1+xxx
#        print("xxx2",xxx)
        return xxx
    elif xx==3+pb[nn-1][0]*2:
        return pb[nn][1]
    else:
        print("----------",xx,nn)
        return 0

    
print(pbx(x,n))


Measured memory_bytes: 9200
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vector<string> s(n);
    rep(i, n) {
        cin >> s[i];
    }

    ll m;
    cin >> m;
    vector<string> t(m);
    rep(i, m) {
        cin >> t[i];
    }

    ll ans = 0;
    rep(i, n) {
        ll now = 0;
        rep(j, n) {
            if(s[j] == s[i]) {
                now++;
            }
        }
        rep(j, m) {
            if(t[j] == s[i]) {
                now--;
            }
        }
        chmax(ans, now);
    }

    out(ans);
    re0;
}

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

string Array[105];

int main(){
	int N,L;
	scanf("%d %d",&N,&L);
	string s;
	for (int i = 0; i < N; ++i)
	{
		cin >> s;
		Array[i]=s;
	}
	sort(Array,Array+N);
	string Con="";
	for (int i = 0; i < N; ++i)
	{
		Con+=Array[i];
	}
	cout << Con;
	return 0;
}

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

int main(){
  int n,maxnum=0;;
  cin>>n;
  int num[n];
  for(int i=0;i<n;i++){
    cin>>num[i];
  }
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      int a=abs(num[i]-num[j]);
      maxnum = max(maxnum,a);
    }
  }
  cout<<maxnum<<endl;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define For(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
typedef vector<long long> vlint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<vector<long long>> vlint2;


int main() {
  lint h, w; cin >> h >> w;
  vector<string> grid(h); rep(i, h) cin >> grid[i];
  
  vector<vector<int>> lr(h+1, vector<int>(w+1));
  vector<vector<int>> ud(h+1, vector<int>(w+1));

  // lr
  int left, right, cnt;
  rep(i, h){
    left = 0;
    right = 0;
    cnt = 0;
    rep(j, w){
      if (grid[i][j] == '#'){
        lr[i][left] += cnt;
        lr[i][right] -= cnt;
        left = right+1;
        right ++;
        cnt = 0;
      }
      else{
        right ++;
        cnt ++;
        if (j == w-1){
          lr[i][left] += cnt;
        }
      }
    }
  }

  //ud
  int up, down, cnt1;
  rep(j, w){
    up = 0;
    down = 0;
    cnt1 = 0;
    rep(i, h){
      if (grid[i][j] == '#'){
        ud[up][j] += cnt1;
        ud[down][j] -= cnt1;
        up = down+1;
        down ++;
        cnt1 = 0;
      }
      else{
        down ++;
        cnt1 ++;
        if (i == h-1){
          ud[up][j] += cnt1;
        }
      }
    }
  }


  rep(i, h){
    rep(j, w){
      lr[i][j+1] += lr[i][j];
      ud[i+1][j] += ud[i][j];
    }
  }

  int ans = 0;
  rep(i, h){
    rep(j, w){
      ans = max(ans, lr[i][j] + ud[i][j] - 1);
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 35840
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+9
#define MOD 1000000007
using namespace std;


int main(){
    int N,Q;
    cin >> N >> Q;
    string s;
    cin >> s;
    int l[100000],r[100000];
    int AC[100000]={};
    for(int i=0; i<N-1; i++){
        if(s[i]=='A' && s[i+1]=='C'){
            AC[i]=1;
        }else{
            AC[i]=0;
        }
    }
    
    for(int i=0; i<Q; i++){
        cin >> l[i] >> r[i];
        l[i]--;
        r[i]--;
    }
    
    int ACsum[100000]={};
    ACsum[0]=AC[0];
    for(int i=1; i<N; i++){
        ACsum[i]=AC[i]+ACsum[i-1];
    }
    
    for(int i=0; i<Q; i++){
        
        if(l[i]==0){
            cout<<ACsum[r[i]-1]<<endl;
        }else{
            cout<< ACsum[r[i]-1]-ACsum[l[i]-1] <<endl;
        }
    }
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  if(n<=9){
    cout << n << endl;
  }
  else if(n<=99){
    cout << 9 << endl;
  }
  else if(n<=999){
    cout << 9 + (n-100+1) << endl;
  }
  else if(n<=9999){
    cout << 9 + (999-100+1) << endl;
  }
  else if(n<=99999){
    cout << 9 + (999-100+1) + (n-10000+1) << endl;
  }
  else{
    cout << 9 + (999-100+1) + (99999-10000+1) << endl;
  }
  
}

Measured memory_bytes: 3608
N = int(input())

def dfs(s):

    if int(s) > N:
        return 0
        
    if set(list(s)) == {"7", "5", "3", "0"}:
        ret = 1
    else:
        ret = 0

    for c in "753":
        ret += dfs(s + c)

    return ret

print(dfs('0'))

Measured memory_bytes: 3316
import collections
a=int(input())
b=input()
result=[]
for i in range(1,a):
    n=b[:i]
    m=b[i:]
    n=collections.Counter(n)
    m=collections.Counter(m)
    n,o1=zip(*n.most_common())
    m,o2=zip(*m.most_common())
    n=set(n)
    m=set(m)
    s_i=n&m
    s_i=len(s_i)
    result.append(s_i)
print(max(result))

Measured memory_bytes: 9332
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    vector<int> l(n * 2);
    for (int i = 0; i < n * 2; i++) {
        cin >> l[i];
    }

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

    int r = 0;
    for (int i = 0; i < n * 2; i += 2) {
        r += l[i];
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
    int n;
    cin >> n;
    set<int> mochi;
    REP(i, n) {
        int tmp;
        cin >> tmp;
        mochi.insert(tmp);
    }
    cout << mochi.size() << '\n';
    return 0;
}

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

using namespace std;



int M, D;


int main(){
    
    cin >> M >> D;
    
    int ans = 0;
    
    if (M > 3 && D >= 22) {
        
        for (int m = 4; m <= M; m++) {
            for (int i = 22; i <= D; i++) {
                int d10 = i/10;
                int d1 = i - d10*10;
                if (d1 >= 2 && d10 >= 2 && d1*d10 == m) {
                    ans += 1;
                }
                
                
            }
        }
        
        
    }
    
    
    
    cout << ans << endl;
    
    
}



Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while(sc.hasNext()){
			String s = sc.next();
			String t = sc.next();
			if(s.length()>t.length()){
				String u = s;
				s = t;
				t = u;
			}
			char[] a = s.toCharArray();
			char[] b = t.toCharArray();
			int ar = a.length;
			int br = b.length;
			int cr, count;
			int max = 0;
			
			for(int i=0;i<ar+br-2;i++){
				count = 0;
				for(int j=0;j<ar;j++){
					cr = br-1-i+j;
					if(0<=cr && cr<br){
						if(a[j]==b[cr]) count++;
						else{
							max = Math.max(max, count);
							count = 0;
						}
					}
				}
				max = Math.max(max, count);
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 21444
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int n; cin >> n;
    arr<int> A(n, vector<int>(n));
    vector<int> opp(n);
    rep(i, n){
        rep(j, n-1) {cin >> A[i][j]; A[i][j]--;}
        A[i][n-1] = -1;
        opp[i] = A[i][0];
    }

    vector<int> IND(n, 0);
    int ans = 0;
    int finished = 0;
    while(finished<n){
        ans++;
        // printf("day %d: ", ans);
        // rep(i, n) cout << opp[i] << " ";
        // pr("");

        vector<bool> seen(n, false);
        int game = 0;
        rep(i, n){
            
            if(IND[i]==n) continue;
            if(seen[i]) continue;
            seen[i] = true;
            if(IND[opp[i]]==n) continue;

            if(i == opp[opp[i]]){
                if(seen[opp[i]]) continue;
                int t = opp[i];
                // printf("%d: %d %d\n", ans+1, i, opp[i]);
                IND[i]++;
                IND[t]++;

                if(IND[i]==n-1) finished++;
                else opp[i] = A[i][IND[i]];

                if(IND[t]==n-1) finished++;
                else opp[t] = A[t][IND[t]];

                seen[t] = true;
                game++;
            }
        }
        if(game==0) {pr(-1); return 0;}
    }

    pr(ans);
    return 0;}

Measured memory_bytes: 7536
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
string s[102];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int r,c;
    cin>>r>>c;
    for(int i=0; i<r; i++)
        cin>>s[i];
    for(int i=0; i<r; i++)
    {
        int cnt=0;
        for(int j=0; j<c; j++)
        {
            if(s[i][j]=='.' || s[i][j]=='X')
                cnt++;
        }
        if(cnt==c)
        {
            for(int j=0; j<c; j++)
                s[i][j]='X';
        }
    }
    for(int j=0; j<c; j++)
    {
        int cnt=0;
        for(int i=0; i<r; i++)
        {
            if(s[i][j]=='.' || s[i][j]=='X')
                cnt++;
        }
        if(cnt==r)
        {
           for(int i=0; i<r; i++)
                s[i][j]='X';
        }
    }
    vector<string>v;
    for(int i=0;i<r;i++){
        string cur="";
        for(int j=0;j<c;j++){
            if(s[i][j]!='X')
                cur+=s[i][j];
        }
        if(cur.size())
            v.push_back(cur);
    }
    for(auto i:v)
        cout<<i<<endl;

    return 0;
}


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

using namespace std;

const int N = 105;

int n;
int a[N];

int main() {

	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	double ans = 0;
	for (int i = 1; i <= n; i ++) {
		ans += 1.0 / a[i];
	}
	ans = 1.0 / ans;
	cout << setprecision(9) << fixed << ans << '\n';
	return 0;
}

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

int main(){
    int n ,j;
  	vector<int> v,v2;
    cin >> n;
  for(int i=0;i<n;i++){
    cin >> j;
    v.push_back(j);
  }
  v2=v;
  sort(v.begin(),v.end());
  for(int i=0;i<n;i++){
  if(v2[i]==v.at(n-1)){
  cout<<v.at(n-2)<<endl;
  }else{
  cout<<v.at(n-1)<<endl;
  }
  }
}

Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

// 区間加算にも対応したBinary Index Tree(1-indexで使うことに気をつける)
template <class Abel> struct BIT {

    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;
    
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    // 区間[a,b)にxを加算する(a, bは1-index)
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    // 区間[a,b)の総和を計算する(a, bは1-index)
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
};

int main() {
    ll n, d, a;
    cin >> n >> d >> a;

    vector<P> p(n);
    rep(i, n) {
        ll x, h;
        cin >> x >> h;
        p[i] = make_pair(x, h);
    }
    sort(all(p));

    vl x(n), h(n);
    rep(i, n) {
        x[i] = p[i].first;
        h[i] = p[i].second;
    }
    
    BIT<ll> bit(n+10);
    rep(i, n) {
        bit.add(i+1, i+2, h[i]);
    }

    ll ans = 0;
    exrep(i, 1, n) {
        ll hp_i = bit.sum(i, i+1);  // モンスタiの体力
        if(hp_i <= 0) {  // モンスタiの体力が0以下の場合
            continue;  // モンスタiはおしまい
        }
        ll cnt = (hp_i + a - 1)/a;  // モンスタiを倒すのに必要な操作回数
        //　モンスタiのいる座標を左端とした爆発が届く範囲を求める
        ll right = x[i-1] + 2*d;  // 爆発が届く右端の座標
        ll id = upper_bound(all(x), right) - x.begin();  // 爆発が届かないモンスタの中で最も左にいるモンスタの番号 
        id++;
        bit.add(i, id, -a*cnt);  // モンスタiからモンスタid-1の体力をa*need減らす
        ans += cnt;
    }

    out(ans);
    re0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
   int n;
   string s;
   int ans;
   cin >> n;

   for(int i=1;i<=n;i++){
      s = to_string(i);
      // 文字列のサイズなので１００だったら3文字になってあまりは1となるから
      if(s.size()%2==1){
         ans++;
      }
   }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

double power(int t, int s){
	return (t-s)*(t-s);
}

int main(){
	int N;cin>>N;
	vector<ip> town(N);
	rep(i,N)cin>>town[i].first>>town[i].second;
	int perm[8] = {0,1,2,3,4,5,6,7};
	double ans = 0;
	int divisor = 0;
	do{
		++divisor;
		for(int i = 0; i<N-1; ++i){
			ans += sqrt(power(town[perm[i]].first, town[perm[i+1]].first) + power(town[perm[i]].second, town[perm[i+1]].second));
		}
	}while(next_permutation(perm, perm+N));
	cout<<fixed<<setprecision(10)<<ans/divisor<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int main () {
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  
  deque<int> dq;
  if (n%2) {
    dq.push_front(a[0]);
    for (int i = 0; i < n-1; i+=2) {
      dq.push_back(a[i+1]);
      dq.push_front(a[i+2]);
    }
  }
  else {
    for (int i = 0; i < n; i+=2) {
      dq.push_back(a[i]);
      dq.push_front(a[i+1]);
    }
  }

  rep(i,dq.size()) printf("%d%c", dq[i], i==dq.size()-1?'\n':' ');
  return 0;
}

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


public class Main {
    static long mod = 1000000000+7;
    static int n,a,b,k;
    static HashMap<Integer,Integer>[] g;
    static int[] ans;
    public static void main(String[] args) throws Exception{
        //Scanner sc = new Scanner(System.in);
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] buf = reader.readLine().split(" ");
        n = Integer.parseInt(buf[0]);
        ans = new int[n+1];
        g = new HashMap[n+1];
        for(int i=0;i<=n;i++) g[i]=new HashMap<>();
        for(int i=0;i<n-1;i++){
            buf = reader.readLine().split(" ");
            int u = Integer.parseInt(buf[0]), v = Integer.parseInt(buf[1]);
            int len = Integer.parseInt(buf[2]);
            g[u].put(v,len); g[v].put(u,len);
        }
        ans[1]=1;
        for(int w:g[1].keySet()) dfs(w,1);
        PrintWriter out = new PrintWriter(System.out);
        for(int i=1;i<=n;i++) out.println(ans[i]);
        out.flush();
    }
    static void dfs(int cur, int from){
        int len = g[cur].get(from);
        if(len%2==0) ans[cur]=ans[from];
        else ans[cur] = 1-ans[from];
        for(int w:g[cur].keySet()){
            if(w==from) continue;
            dfs(w,cur);
        }
    }
}



Measured memory_bytes: 90676
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define llinf (1ll<<60)
#define BG(x) ((x).begin())
#define ED(x) ((x).end())
#define rBG(x) ((x).rbegin())
#define rED(x) ((x).rend())
#define mp(a, b) make_pair((a), (b))

ll t;

ll n;
vector<ll> prime;
bitset<1000005> is_prime;
map<ll, ll> fact;
vector<ll> fib{1, 2};

void gen_prime() {
	is_prime.set();
	for(int i = 2; i < 1000005; i++) {
		if(is_prime[i]) {
			prime.push_back(i);
			for(int j = i+i; j < 1000005; j += i)
				is_prime[j] = 0;
		}
	}
}

void gen_fib() {
	while(1) {
		fib.push_back(*(rBG(fib))+*(rBG(fib)+1));
	//	cout << *rBG(fib) << '\n';
		if(*rBG(fib) > 1000005)
			break;
	}
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
//    cin >> t;
    t = 1;
	
    for(int _ = 1; _ <= t; _++) {
    //    cout << "Case #" << _ << ": ";
        
		gen_prime();
		gen_fib();
		cin >> n;
		
		for(auto x : prime) {
			while(!(n%x)) {
				fact[x]++;
				n /= x;
			}
		}
		if(n != 1)
			fact[n]++;
		
		ll ans = 0;
		for(auto x : fact) {
			ll temp = x.second;
			for(int i = 1; i <= temp; i++) {
				ans++;
				temp -= i;
			}
		//	ans += upper_bound(BG(fib), ED(fib), x.second) - BG(fib);
		//	cout << ans << '\n';
		}
		cout << ans << '\n';
    }
	
    return 0;
}

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

int main() {
    string S;
    int num0=0, num1=0;

    cin >> S;
    for (int i=0; i<S.size(); i++) {
        if (S[i] == '0') num0++;
        else num1++;
    }

    cout << min(num0, num1) * 2 << endl;

    return 0;

}


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

int main() {
	std::size_t n;
	long long k;
	std::cin >> n >> k;
	std::vector<long long> a(n), b(n);
	for (std::size_t i = 0; i < n; i++) {
		std::cin >> a[i] >> b[i];
	}

	auto solve = [&] (long long x) -> long long {
		long long value = 0;
		for (std::size_t i = 0; i < n; i++) {
			if ((x | a[i]) == x) value += b[i];
		}
		return value;
	};

	long long ans = solve(k);
	for (long long s = 1; s <= (k << 1); s <<= 1) {
		long long x = (s - 1);
		for (long long p = (1LL << 35); p > 0; p >>= 1) {
			if ((x | p) <= k) x |= p;
		}
		if (x <= k) ans = std::max(ans, solve(x));
	}

	std::cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 4856
import java.util.*;

class Main {

    static void solve (char [][] field) {
        boolean found = false;
        int y = 0;
        int x = 0;

        for(int i = 0; i < 8; i++) {
            for(int j = 0; j < 8; j++) {
                if((!found) && field[i][j] == '1') {
                    y = i;
                    x = j;
                    found = true;
                }
            }
        }

        if( x < 7 && field[y][x+1] == '1' ) {   // 右どなりにもブロックがあるとき
            if ( x < 6 && field[y][x+2] == '1' ) {  // 2 つとなりにもブロックがあるとき
                System.out.println("C");
                return;
            }
            if ( y < 7 && field[y+1][x] == '1' ) {  // 1 つ下にもブロックがあるとき
                if ( field[y+1][x+1] == '1') {      // 右下にもブロックがあるとき
                    System.out.println("A");
                    return;
                }
                System.out.println("G");
                return;
            }
            System.out.println("E");
            return;
        }
        if ( x < 7 && field[y+1][x+1] == '1') {
            System.out.println("F");
            return;
        }
        if ( x > 0 && field[y+1][x-1] == '1') {
            System.out.println("D");
            return;
        }
        System.out.println("B");
        return;
    }

    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);
       
        char [][] field = new char [8][8];

        while(sc.hasNext()) {

            for(int i = 0; i < 8; i++) {
                field[i] = sc.nextLine().toCharArray();
            }
            if(sc.hasNext()) sc.nextLine();

            solve(field);
        }

    }
}

Measured memory_bytes: 12000
import sys
input = sys.stdin.readline
x,y,a, b, c = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ans = sum(A[:x]) + sum(B[:y])
ans0 = ans
import heapq
Q = []
for i in range(x):
    heapq.heappush(Q, A[i])
for i in range(y):
    heapq.heappush(Q, B[i])

for i in range(c):
    # print(Q)
    p = heapq.heappop(Q)
    # print(p)
    ans0 = ans0 - p + C[i]
    # print(p, C[i],ans0)
    ans = max(ans, ans0)
    heapq.heappush(Q, C[i])
print(ans)

Measured memory_bytes: 105128
#include <bits/stdc++.h>
//#pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll infll=(1ull<<63)-1;
const int inf=(1ull<<31)-1;
ll t;
ll s=0;
vector<ll> v;

int main()
{
	//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cout.precision(18);
	cin>>t;
	for (;t;v.push_back(t%10),t/=10);
	reverse(v.begin(),v.end());
	int m=v.size(),n=1<<(m-1);
	for (int i=0;i<n;i++){
		ll y=0;
		for (int j=m-2;j>=0;j--){
			y=y*10+v[m-j-2];
			if ((i>>j)&1){
				s+=y;
				y=0;
			}
		}
		y=y*10+v[m-1];
		s+=y;
	}
	cout<<s;
	return 0;
}

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

int main(int argc, char *argv[])
{
    int n, m, p, k, l;
    while (cin >> n, n) {
        vector<vector<int> > data(n);
        vector<int> leaked;
        vector<int> suspect;
        vector<int>::iterator itr;
        for (int i = 0; i < n; ++i) {
            cin >> m;
            for (int j = 0; j < m; ++j) {
                cin >> p;
                data[i].push_back(p);
            }
        }
        cin >> k;
        for (int i = 0; i < k; ++i) {
            cin >> l;
            leaked.push_back(l);
        }
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < k; ++j) {
                itr = find(data[i].begin(), data[i].end(), leaked[j]);
                if (itr == data[i].end())
                    break;
            }
            if (itr != data[i].end())
                suspect.push_back(i + 1);
        }
        if (suspect.size() == 1)
            cout << suspect[0] << endl;
        else
            cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1272
#include<stdio.h>
bool field[16][16];
int solve(int row,int col){
	int ret=0;
	if(row+col==0)return 1;
	if(row>0&&field[row-1][col])ret+=solve(row-1,col);
	if(col>0&&field[row][col-1])ret+=solve(row,col-1);
	return ret;
}
int main(){
	while(1){
		int a,b;
		scanf("%d%d",&a,&b);
		if(a+b==0)return a+b;
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)field[i][j]=true;
		int c;
		scanf("%d",&c);
		for(int i=0;i<c;i++){
			int x,y;
			scanf("%d%d",&x,&y);
			x--;
			y--;
			field[x][y]=false;
		}
		printf("%d\n",solve(a-1,b-1));
	}
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  // エラトステネスのふるい
  int MAX = 101010;
  vector<int> is_prime(MAX, 1);
  is_prime[0] = 0, is_prime[1] = 0;
  for (int i = 2; i < MAX; ++i) {
    if (!is_prime[i]) continue;
    for (int j = i * 2; j < MAX; j += i) is_prime[j] = 0;
  }

  // 2017-like 数かどうか
  vector<int> a(MAX, 0);
  for (int i = 0; i < MAX; ++i) {
    if (i % 2 == 0) continue;
    if (is_prime[i] && is_prime[(i + 1) / 2]) a[i] = 1;
  }

  // 累積和
  vector<int> s(MAX + 1, 0);
  for (int i = 0; i < MAX; ++i) s[i + 1] = s[i] + a[i];

  // クエリ処理
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    ++r;

    cout << s[r] - s[l] << endl;
  }
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

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

    public double nextDouble() {
      return Double.parseDouble(next());
    }

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

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

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    String n = sc.next();
    System.out.println(n.contains("7") ? "Yes" : "No");
  }
}

Measured memory_bytes: 25316
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  if (A==1){
    A=14;
  }
  if (B==1){
    B=14;
  }
  if (A>B){
    cout << "Alice" << endl;
  }
  else if (A<B){
    cout << "Bob" << endl;
  }
  else {
    cout << "Draw" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define sl set<ll>
#define vs vector<string>
#define vl vector<ll>
#define vi vector<int>
#define vpl vector<pair<ll,ll>>
#define pb push_back
#define PI 3.14159265358979323846
#define ll long long
#define ld long double
#define endl "\n"
#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define repp(i,a,b) for (ll i = (a); i >= (b); i--)
#define rop(i,a,b)  for(ll i=(a); i>(b); i--)
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define tt long long t; cin>>t; while(t--)
#define IOS ios::sync_with_stdio(0);cin.tie(0);
const int maxn=1e5+100;


int main()
{ int n,d,cnt=0,x,y;
 cin>>n>>d;
while(n--)
{ cin>>x>>y;
 if(sqrt(pow(abs(x),2)+pow(abs(y),2))<=d) cnt++;
}
 cout<<cnt;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

int main() {
    int n; cin >> n;
    vint a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    cout << a[n-1]-a[0] << endl;
}

Measured memory_bytes: 256
def prime_factorization(n):
    if n == 1:
        return []
    ret = []
    tmp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if tmp%i==0:
            cnt=0
            while tmp%i==0:
                cnt+=1
                tmp//=i
            ret.append([i, cnt])
    if tmp!=1:
        ret.append([tmp,1])
    if ret==[]:
        ret.append([n,1])
    ret.sort()
    return ret

N = int(input())
P = prime_factorization(N)
ans = 0

for prime in P:
    cnt = 1
    while cnt <= prime[1]:
        ans += 1
        prime[1] -= cnt
        cnt += 1
print(ans)

Measured memory_bytes: 9492
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n0 = int(input())
    c0 = list(map(int, readline().split()))
    c0.sort(reverse=True)

    ans = 0
    mul = pow(2, n0 - 1, MOD)
    add = pow(2, max(0, n0 - 2), MOD)

    for i, cc in enumerate(c0, 1):
        ans += cc * mul
        ans %= MOD
        mul += add
        mul %= MOD

    ans *= pow(2, n0, MOD)
    ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 78676
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)


int main(){
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    ll asum = 0;
    ll bsum = 0;
    vector<ll> ex(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        asum += a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
        bsum += b[i];
    }
    for(int i = 0; i < n; i++){
        ex[i] = a[i]-b[i];
    }
    if(asum<bsum){
        cout << -1 << endl;
        return 0;
    }
    sort(ex.begin(),ex.end());
    ll minus = 0;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        if(ex[i]<0){
            minus += (-1)*ex[i];
            ans++;
        }else{
            break;
        }
    }
    if(minus==0){
        cout << ans << endl;
        return 0;
    }
    for(int i = 0; i < n; i++){
        minus -= ex[n-1-i];
        ans++;
        if(minus <= 0){
            break;
        }
    }
    cout << ans << endl;

    return 0;
}


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

const int N=2e5+5;
const int MOD=998244353;
int n,m=1,q;
int wt[N];
int lson[N*2],rson[N*2],val[N*2],tag[N*2],siz[N*2];

void selfupd(int pos){
	val[pos]=1ll*tag[pos]*siz[pos]%MOD;
}

void update(int pos){
	val[pos]=(val[lson[pos]]+val[rson[pos]])%MOD;
}

void build(int pos,int x,int y){
	if(x==y){
		siz[pos]=val[pos]=wt[x];
		return;
	}
	int mid=(x+y)>>1;
	lson[pos]=++m;
	rson[pos]=++m;
	build(lson[pos],x,mid);
	build(rson[pos],mid+1,y);
	siz[pos]=(siz[lson[pos]]+siz[rson[pos]])%MOD;
	update(pos);
}

void pushdown(int pos){
	if(tag[pos]){
		tag[lson[pos]]=tag[pos];
		tag[rson[pos]]=tag[pos];
		tag[pos]=0;
		selfupd(lson[pos]);
		selfupd(rson[pos]);
	}
}

void modify(int pos,int x,int y,int l,int r,int v){
	if(x>=l&&y<=r){
		tag[pos]=v;
		selfupd(pos);
		return;
	}
	if(x>r||y<l) return;
	int mid=(x+y)>>1;
	pushdown(pos);
	modify(lson[pos],x,mid,l,r,v);
	modify(rson[pos],mid+1,y,l,r,v);
	update(pos);
}

int main(){
	scanf("%d%d",&n,&q);
	wt[n]=1;
	for(int i=n-1;i>=1;i--) wt[i]=10ll*wt[i+1]%MOD;
	build(1,1,n);
	while(q--){
		int l,r,v;
		scanf("%d%d%d",&l,&r,&v);
		modify(1,1,n,l,r,v);
		printf("%d\n",val[1]);
	}
	return 0;
}

Measured memory_bytes: 12412
#include<iostream>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  
  int A[N];
  int B[N-1];
  for(int i=0; i<N-1; i++){
    cin >> B[i];
  }
  
  if(N==2){
    A[0] = B[0];
    A[1] = B[0];
  }else{
    for(int j=1; j<N-1; j++){
      if(B[j-1]<=B[j]){
        A[j] = B[j-1];
      }else{
        A[j] = B[j];
      }
    }
    A[0] = B[0];
    A[N-1] = B[N-2];
  }
  
  
  int sum = 0;
  for(int k=0; k<N; k++){
    sum += A[k];
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1000000007;
const long long INF = 1LL << 60;
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s,t;
    int ans = 0;
    cin >> s >>t;
    rep(i,3)if(s[i] == t[i]) ans++;
    cout << ans <<endl;
}

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

string Str;
vector< string > Ret;
void Dfs(string s, int used, int idx){
  if(idx == Str.size()){
    Ret.push_back(s);
    return;
  }
  char c = Str[idx];
  if((used >> (c - 'a')) & 1){ //既に現れている文字
    Dfs( s + c, used, idx + 1);
  }
  if(c != 'z' && !((used >> (c + 1 - 'a')) & 1)){
    Dfs( s + (char)(c + 1), used|(1 << (c + 1 - 'a')), idx + 1);
  }
  return;
}
int main(){
  while(cin >> Str, Str != "#"){
    Dfs("", 1, 0);
    cout << Ret.size() << endl;
    if(Ret.size() < 10){
      for(int i = 0; i < Ret.size(); i++){
        cout << Ret[i] << endl;
      }
    } else {
      for(int i = 0; i < 5; i++){
        cout << Ret[i] << endl;
      }
      for(int i = Ret.size() - 5; i < Ret.size(); i++){
        cout << Ret[i] << endl;
      }
    }
    Ret.clear();
  }
}

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

int main()
{
    int n;
    cin>>n;
    int arr[n][3],dp[n][3];
    for(int i=0;i<n;i++)
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    dp[0][0]=arr[0][0];
    dp[0][1]=arr[0][1];
    dp[0][2]=arr[0][2];
    for(int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1]+arr[i][0],dp[i-1][2]+arr[i][0]);
        if(i!=1)
            dp[i][0]=max(dp[i][0],dp[i-2][0]+arr[i][0]);
        dp[i][1]=max(dp[i-1][0]+arr[i][1],dp[i-1][2]+arr[i][1]);
        if(i!=1)
            dp[i][1]=max(dp[i][1],dp[i-2][1]+arr[i][1]);
        dp[i][2]=max(dp[i-1][1]+arr[i][2],dp[i-1][0]+arr[i][2]);
        if(i!=1)
            dp[i][2]=max(dp[i][2],dp[i-2][2]+arr[i][2]);
    }
    int ans= max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  int ac = 0, wa = 0, tle = 0, re = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s == "AC")
      ac++;
    else if (s == "WA")
      wa++;
    else if (s == "TLE")
      tle++;
    else if (s == "RE")
      re++;
  }
  cout << "AC "
       << "x " << ac << endl;
  cout << "WA "
       << "x " << wa << endl;
  cout << "TLE "
       << "x " << tle << endl;
  cout << "RE "
       << "x " << re << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
#define DIV0 1000000007
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

*/
int main()
{
    int N;
    cin >> N;
    ll A[N];
    REP(i,N) cin >> A[i];

    //総和をとってかけて、対角要素を引いて、2で割る
    
    /*ll ans = 0;
    REP(i,N) ans = (ans + A[i])%DIV0;
    ans = (ans * ans)%DIV0;
    REP(i,N) ans = (ans - A[i]*A[i] + DIV0)%DIV0;
    ans = (ans/2 + DIV0)%DIV0;*/
    ll sum[N];
    sum[0] = A[0];
    REPD(i,1,N) sum[i] = (sum[i-1] + A[i])%DIV0;
    ll ans = 0;
    REPD(i,1,N) ans = (ans + A[i] * sum[i-1])%DIV0;

    fin(ans);
    return 0;
}

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

using namespace std;

vector<int> s(const vector<int>& v,int n){
	vector<int> v1;
	for(int i = 0; i < n; i++){
		v1.push_back(v[i]);
		v1.push_back(v[i+n]);
	}
	return v1;
}

vector<int> k(const vector<int>& v, int m){
	vector<int> v1;
	for(int i = m; i < v.size(); i++){
		v1.push_back(v[i]);
	}
	for(int i = 0; i < m; i++){
		v1.push_back(v[i]);
	}
	return v1;
}


int main(){
	int n, m, sh;
	cin >> n;
	vector<int> deck;
	for(int i = 1; i <= 2*n; i++){
		deck.push_back(i);
	}
	cin >> m;
	for(int i = 0; i < m; i++){
		cin >> sh;
		if(sh == 0){
			deck = s(deck,n);
		}
		else{
			deck = k(deck,sh);
		}
	}
	for(unsigned int i = 0; i < deck.size(); i++){
		cout << deck[i] << endl;
	}
}

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

int main()
{
    int H, W;
    cin >> H >> W;
    vector<vector<char>> Pic(H + 2, vector<char>(W + 2, '#'));
    for (int h = 1; h < H + 1; ++h){
        for (int w = 1; w < W + 1; ++w){
            cin >> Pic[h][w];
        }
    }

    for (int h = 0; h < H + 2; ++h)
    {
        for (int w = 0; w < W + 2; ++w)
        {
            cout << Pic[h][w];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
from itertools import accumulate
from bisect import bisect_left
W, H = map(int, input().split())
W_cost = sorted([int(input()) for i in range(W)])
H_cost = [int(input()) for i in range(H)]


# 横は全部辺を張り、縦は各区間1本
W_cost_sum = sum(W_cost)
ans = W_cost_sum * (H + 1) + sum(H_cost)


W_acc_cost = [0] + list(accumulate(W_cost))
for h in H_cost:
    hx = bisect_left(W_cost, h)
    ans -= (W_cost_sum - W_acc_cost[hx]) - ((W - hx) * h)

print(ans)


Measured memory_bytes: 16512
K = int(input())
S = list(map(int, input().split()))

m = [0]*K
M = [0]*K
m[K-1] = 2
M[K-1] = 3
if S[K-1] != 2:
    print(-1)
else:
    for i in range(K-2, -1, -1):
        if m[i+1]%S[i] == 0:
            m[i] = m[i+1]
        else:
            m[i] = m[i+1]+S[i]-(m[i+1]%S[i])
        if M[i+1]%S[i] == 0:
            M[i] = M[i+1]+S[i]-1
        else:
            M[i] = (M[i+1]//S[i])*S[i]+S[i]-1
        if m[0] > M[0]:
            print(-1)
            break
    else:
        print(m[0], M[0])


Measured memory_bytes: 20944
#include<bits/stdc++.h>
#define mk make_pair
using namespace std;
const int N=1e5+100;
const int mod=998244353;
typedef long long ll;
void test(){
    printf("  ***////   \n");
}
int a[N];
int main() {
    int n;
    scanf("%d",&n);
    map<int,int> mp;
    int maxe=-1;
    scanf("%d",&a[0]);
    mp[a[0]]++;
    bool vis=false;
    for(int i=1;i<n;i++){
        scanf("%d",&a[i]);
        if(!a[i])
            vis=true;
        maxe=max(maxe,a[i]);
        mp[a[i]]++;
    }
    if(a[0]||vis){
        printf("0\n");
        return 0;
    }
    //test();
    ll ans=1;
    for(int i=1;i<n;i++){
        ans=(ans*mp[a[i]-1])%mod;
    }
    cout<<ans<<endl;
    return 0;
}
/*
3
8 5
11011010
7 9
1111100
7 10
1111100

*/


Measured memory_bytes: 5376
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N, L;
    cin >> N >> L;
    vector<pii> vp(N);
    rep(i, N) {
        int p, d;
        cin >> p >> d;
        vp[i] = MP(p, d);
    }
    sort(All(vp));
    ll res = 0;
    rep(i, N) {
        if(vp[i].second == 0) {
            res += vp[i].first - (i + 1);
        } else {
            res -= vp[i].first - (i + 1);
        }
    }
    ll tmp = res;
    int c = 0;
    for(int i = N - 1; i >= 0; i--) {
        if(vp[i].second == 0) {
            tmp -= L - c - (i + 1);
        } else {
            tmp += L - c - (i + 1);
        }
        c++;
        res = max(res, tmp);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3536
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

  if(s[0] == 'S'){
    cout << "Cloudy" << endl;
  } else if(s[0] == 'C'){
    cout << "Rainy" << endl;
  } else if(s[0] == 'R'){
    cout << "Sunny" << endl;
  }

  return 0;
}


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

using namespace std;

int main(int argc, char *argv[]) {
    string N;
    cin >> N;

    int ans = 0;
    for (int i = 0; i < N.size(); i++) {
        if (N[i] == '2') {
            ans++;
        }
    }
    cout << ans << endl;
        return 0;
}


Measured memory_bytes: 256
//============================================================================
// Name        : aoj0096.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstring>

using namespace std;

int main() {
	long long n, dp[5][4001];
	memset(dp,0,sizeof(dp));
	dp[0][0] = 1;
	while(cin >> n){
		for(int i = 1;i <= 4;i++){
			for(int j = 0;j <= n;j++){
				if(j - 1001 >= 0){
					dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1001];
				}else{
					dp[i][j] = dp[i][j - 1] + dp[i - 1][j];
				}
			}
		}
		cout << dp[4][n] << endl;
	}
	return 0;
}

Measured memory_bytes: 1320