akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define ASSERT(expr...) assert((expr))

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;
using ll = long long;

constexpr i64 INF = 1010000000000000017LL;

constexpr i64 MOD = 1000000007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

ll mod_pow(ll x, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        return mod_pow(x * x % MOD, n / 2) % MOD;
    } else {
        return x * mod_pow(x, (n - 1)) % MOD;
    }
}

ll mod_pow_r(ll x, ll n) {
    if (x == 0) return 0;
    if (n == 0) return 1;

    ll ret = 1;
    while (n) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n /= 2;
    }
    return ret;
}

ll factorial(ll n) {
    ll ret = 1;
    REP(i, n) {
        ret *= (i + 1);
        ret %= MOD;
    }
    return ret;
}

ll combination(ll n, ll r) {
    if (n < 0 || n < r || r < 0) return 0;
    ll fn = factorial(n);
    ll fr = factorial(r);
    ll fn_r = factorial(n-r);

    ll d = (mod_pow(fr, MOD - 2) * mod_pow(fn_r, MOD - 2)) % MOD;
    ll u = fn % MOD;
    return u * d % MOD;
}

void solve() {
    ll k, n; cin >> k >> n;
    vector<ll> a(n);
    for(ll& x : a) cin >> x;
    ll max = k + a.front() - a.back();
    FOR(i, 0, n-1) {
        ll x = a[i+1] - a[i];
        chmax(max, x);
    }
    cout << k-max;
}

signed main() {
    solve();
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define mod             1000000007
#define w(x)            int x; cin>>x; while(x--)
#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll              long long
 
 
int main() {
    fast
    int n, k;
    cin >> n >> k;
    unordered_set<int> set;
    for(int i = 0; i < k; i++) {
        int d;
        cin >> d;
        for(int j = 0; j < d; j++) {
            int temp;
            cin >> temp;
            set.insert(temp);
        }
    }
    cout <<  n - set.size() << endl;
    return 0;
}

Measured memory_bytes: 3660
// abc141_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N-1);
    REP(i, N) {cin >> A[i]; A[i]--;}
    REP(i, N) cin >> B[i];
    REP(i, N-1) cin >> C[i];

    int ans = 0;
    REP(i, N){
        ans += B[A[i]];
        if (i > 0 && A[i-1] + 1 == A[i]){
            ans += C[A[i-1]];
        }
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 256
//In The Name Of Godd
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<string> vs;
typedef pair<ll, ll> ii;
typedef pair<int, ii> iii;
typedef pair<double, double> dd;
typedef pair<dd, double> ddd;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<dd> vdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vii> vvii;

#define forn(i, n) for (ll i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define inf 100000000000
#define eps 1e-9
const int maxn = 3010;
ll dp[maxn][maxn];

int main() {
  string s, t; cin >> s >> t;
  forn(i, maxn) forn(j, maxn) dp[i][j] = -inf;
  forn(i, s.size()) forn(j, t.size()) {
    if(s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
    else dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
  }
  string ans;
  int i = s.size(), j = t.size();
  while(i != 0 || j != 0) {
    if(i - 1 >= 0 && j - 1 >= 0 && s[i - 1] == t[j - 1]) {
      ans += t[j - 1], i--, j--;
    }
    else if(i - 1 >= 0 && dp[i - 1][j] == dp[i][j]) i--;
    else j--;
  }
  reverse(all(ans));
  cout << ans << endl;
}


Measured memory_bytes: 71040
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int max = Math.max(a, Math.max(b, c));
		int other = a+b+c-max;
		int K = sc.nextInt();
		for(int i=0;i<K;++i) max *= 2;
		System.out.println(max+other);
		return;
	}
}

Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <math.h>
using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;
	int ret = 0;
	if (A > B)
	{
		ret = A--;
	}
	else
	{
		ret = B--;
	}

	if (A > B)
	{
		ret += A--;
	}
	else
	{
		ret += B--;
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin>>n;
    ll MAX = 0;
    vector<ll>a(n);
    rep(i,n){
        ll A;cin>>A;
        MAX = max(A, MAX);
        a[i]=A;
    }
    ll ans = -1;
    ll MA = -1;
    for(ll A:a){
        if(A==MAX)continue;
        if(MA<A&&MA<MAX-A){ans=A;MA=min(A,MAX-A);}
    }
    cout<<MAX<<" "<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3884
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)
bool a[500][500] = {};
char c[500][500];
bool search(int x,int w,int h,int y) {
	if (x < 0 || x >= w || y < 0 || y >= h) {
		return false;

	}
	else if (c[y][x] == '#') {
		return false;
	}
	if (a[y][x] == true) {
		return false;
	}
	if (c[y][x] == 'g') {
		return true;
	}
	a[y][x] = true;
	if (search(x + 1, w, h, y) || search(x - 1, w, h, y) || search(x, w, h, y + 1) || search(x, w, h, y - 1)) {
		return true;
	}
	else {
		return false;
	}

}

//小文字=大文字+32
int main() {
	int n;
	cin >> n;
	vector<int>b(n-1);
	vector<int>a(n);
	rep(i, n-1) {
		cin >> b[i];
	}
	a[0] = b[0];
	for(int i=1;i<n-1;i++){
		a[i] = min(b[i], b[i - 1]);
	}
	a[n - 1] = b[n-2];
	ll ans=0;
	rep(i, n) {
		ans += a[i];
	}
	cout << ans;
}
	



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

using namespace std;

using ll = long long;

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

    ll n, X;

    cin >> n >> X;
    vector<ll> x(n + 1);
    for (int i = 1; i <= n; ++i) cin >> x[i];
    for (int i = 1; i <= n; ++i) x[i] += x[i - 1];

    ll min_e = numeric_limits<ll>::max();
    for (ll k = n; 1 <= k; --k) {
        ll sum = 0, id = 1;
        for (ll r = n, l; 1 <= r && (sum + k * X) < min_e; r = l - 1) {
            l = max(1ll, r - k + 1);
            sum += (id == 1 ? 5 : 2 * id + 1) * (x[r] - x[l - 1]);
            ++id;
        }
        min_e = min(min_e, sum + k * X);
    }

    cout << min_e + n * X << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char C;
  cin >> C;
 
  if(C=='a'||C=='i'||C=='u'||C=='e'||C=='o')
  { 
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

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



int main(){
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<s.size();i++){
		ans+=(s[i]-'0');
	}
	if(ans%9==0){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 3744
#include<cstdio>
using namespace std;
const int maxn=1000005,TT=998244353;
int n,num[maxn],inc[maxn],f[maxn],mu[maxn],p[maxn],ans;
bool vis[maxn];
inline void add(int&x,int y){if((x+=y)>=TT) x-=TT;}
inline void dec(int&x,int y){if((x-=y)<0) x+=TT;}
inline char nc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
	int ret=0;bool f=0;char ch=nc();
	while(ch>'9'||ch<'0') f^=ch=='-',ch=nc();
	while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=nc();
	return f?-ret:ret;
}
inline long long pow(int x,int y){
	long long ret=1,w=x;
	while(1){
		if(y&1) ret=ret*w%TT;
		if(!(y>>=1)) return ret;
		w=w*w%TT;
	}
}
void make(){
	vis[mu[1]=1]=1;
	for (int i=2;i<=n;i++){
		if(!vis[i]) p[++p[0]]=i,mu[i]=-1;
		for (int j=1;j<=p[0];j++){
			if(1ll*i*p[j]>n) break;
			vis[i*p[j]]=1;
			mu[i*p[j]]=-mu[i];
			if(i%p[j]==0){
				mu[i*p[j]]=0;
				break;
			}
		}
	}
}
int main(){
	n=read();
	for (int i=1;i<=n;i++){
		int x=read();
		add(num[x],x),dec(ans,x);
	}
	n=1000000;
	for (int i=1;i<=n;i++)
	for (int j=i+i;j<=n;j+=i) add(num[i],num[j]);
	for (int i=1;i<=n;i++) inc[i]=pow(i,TT-2);
	make();
	for (int i=1;i<=n;i++) if(mu[i]<0) mu[i]+=TT;
	for (int i=1;i<=n;i++)
	for (int j=1,k=i;k<=n;j++,k+=i)
	add(f[k],1ll*inc[i]*mu[j]%TT);
	for (int i=1;i<=n;i++)
	add(ans,1ll*f[i]*num[i]%TT*num[i]%TT);
	printf("%lld\n",1ll*ans*(TT+1>>1)%TT);
	return 0;
}

Measured memory_bytes: 17920
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <algorithm>

#define fin stdin
#define fout stdout
//FILE *fin = fopen("a.in", "r"), *fout = fopen("a.out", "w");

#define MAXN 109

std::vector < int > a[MAXN][MAXN], g[MAXN], mat[MAXN], ans[MAXN];
int n, fata[MAXN], baiat[MAXN];
bool viz[MAXN];

bool gasim(int x) {
    if (viz[x])
        return 0;
    viz[x] = 1;

    for (auto &y : g[x]) {
        if (baiat[y] == 0) {
            fata[x] = y;
            baiat[y] = x;
            return 1;
        }
    }

    for (auto &y : g[x]) {
        if (gasim(baiat[y])) {
            fata[x] = y;
            baiat[y] = x;
            return 1;
        }
    }

    return 0;
}

inline void cuplaj() {
    memset(fata, 0, sizeof fata);
    memset(baiat, 0, sizeof baiat);
    bool f = 1;
    for (int i = 1; i <= n; i++) {
        g[i].clear();
        for (int j = 1; j <= n; j++)
            if (!a[i][j].empty())
                g[i].push_back(j);
    }
    while (f) {
        f = 0;
        memset(viz, 0, sizeof viz);
        for (int i = 1; i <= n; i++)
            if (fata[i] == 0)
                f |= gasim(i);
    }
}

int main() {
    int m;
    fscanf(fin, "%d%d", &n, &m);

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            int x;
            fscanf(fin, "%d", &x);

            a[i][(x - 1) / m + 1].push_back(x);
        }
    }

    for (int i = 1; i <= m; i++) {
        cuplaj();
        for (int j = 1; j <= n; j++) {
            if (fata[j] == 0)
                exit(1);
            mat[j].push_back(a[j][fata[j]].back());
            a[j][fata[j]].pop_back();
        }
    }

    for (int i = 1; i <= n; i++, fprintf(fout, "\n"))
        for (auto &x : mat[i])
            fprintf(fout, "%d ", x);

    for (int i = 1; i <= m; i++) {
        std::vector < int > avem;
        for (int l = 1; l <= n; l++)
            avem.push_back(mat[l][i - 1]);
        std::sort(avem.begin(), avem.end());
        for (int l = 0; l < n; l++)
            ans[l].push_back(avem[l]);
    }

    for (int i = 0; i < n; i++, fprintf(fout, "\n"))
        for (auto &x : ans[i])
            fprintf(fout, "%d ", x);

    fclose(fin);
    fclose(fout);
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1000000009;
const ll LINF = 1e18;

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  for (int i = a; i <= b; ++i) {
    if (i % k != 0) continue;
    cout << "OK\n";
    return 0;
  }
  cout << "NG\n";
  return 0;
}


Measured memory_bytes: 3020
import java.util.*;

public class Main {

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

        int h = sc.nextInt();
        int w = sc.nextInt();

        char array[][] = new char[h][w];

        for (int i = 0; i < h; i++) {
            String str = sc.next();
            for (int j = 0; j < w; j++) {
                array[i][j] = str.charAt(j);
            }
        }

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (array[i][j] == '#') {
                    System.out.print('#');
                } else {
                    int ans = 0;
                    for (int k = 0; k < 3; k++) {
                        for (int l = 0; l < 3; l++) {
                            int col = i + k - 1;
                            int row = j + l - 1;
                            if ( col > -1 && col < h) {
                                if (row > -1 && row < w) {
                                    if (array[col][row] == '#') {
                                        ans++;
                                    }
                                }
                            }

                        }
                    }
                    System.out.print(ans);
                }
            }
            System.out.println();
        }

        sc.close();

    }

}

Measured memory_bytes: 36648
#include <stdio.h>
#include <stdlib.h>
int main(){
  int A[1000];
  int i,j,v,k;
  int N;
  scanf("%d",&N);
  if (N > 100 || N <0)exit(1);
  for (i = 0; i < N; i++){
    scanf("%d",&A[i]);
   
}

 
  for (i = 0; i < N; i++){
    
    v = A[i];
    j = i - 1;
    while(j >= 0 && A[j] >v){
     
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }

     for (k = 0; k < N-1; k++){
    printf("%d ",A[k]);
}
     printf("%d",A[k]);
     printf("\n");
  }
  return 0;
}

Measured memory_bytes: 608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scanner = new Scanner(System.in);
 
		int X =scanner.nextInt();
		int Y =scanner.nextInt();
		int Z =scanner.nextInt();
		 
		int A = X ;
		int B = Y ;
		int C = Z ;
		
		int t ;
		
      //tにAの中身を入れて移動
		t=  A ;
		A = B ;
		B = t ;
		
      //tにAの中身を入れて移動
	    t = A ;
		A = C ;
		C = t ;
	
		System.out.println( A + " " + B + " " + C );
    }
}

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

using namespace std;

int main(){
  long long i,j=0,N;
  cin >> N;
  
  for(i=0;i<=N;i++){
    if(i%3==0 || i%5==0){
      continue;
    }else{
      j+=i;
    }
  }
  
  cout << j << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+5;
struct edge{
	int nxt,to;
}e[N];
int head[N],cnt,in[N];
void add(int x,int y){
	in[y]++;
	e[++cnt].to=y; e[cnt].nxt=head[x]; head[x]=cnt;
} 
int ans[N];queue<int> q;
char S[N];
signed main(){
	cin>>S+1;
	int len=strlen(S+1);
	for(int i=1;i<=len;++i){
		if(S[i]=='<') add(i,i+1);
		else add(i+1,i);
	}
	int n=len+1;
	for(int i=1;i<=n;++i)
		if(!in[i]) q.push(i);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=head[u];i;i=e[i].nxt){
			int v=e[i].to;
			in[v]--;ans[v]=max(ans[u]+1,ans[v]);
			if(!in[v]) q.push(v);
		}
	}
	int sum=0;
	for(int i=1;i<=n;++i)
		sum+=ans[i];
	cout<<sum;
	return 0;
}

Measured memory_bytes: 24740
import qualified Data.Map.Strict as M
import Data.List
import Control.Monad

count :: [Char] -> M.Map Char Int
count = foldl' step $ M.fromList [(ini, 0) | ini <- "MARCH"]
  where step tbl ch
          | ch `elem` "MARCH" = M.adjust (1+) ch tbl
          | otherwise = tbl

choices :: [[Char]]
choices = nub $ map (sort . take 3) $ permutations "MARCH"

patterns :: M.Map Char Int -> Int
patterns tbl = sum [ product $ map (tbl M.!) l
                   | l <- choices ]

main :: IO ()
main = do
  n <- readLn
  ss <- replicateM n getLine
  let table = count $ map head ss
  print $ patterns table


Measured memory_bytes: 48508
n=int(input())
S=[]
for i in range(n):
    S.append(input())
S=sorted(S)
from collections import defaultdict
d = defaultdict(int)

for k in S:
    d[k]+=1

d=dict(d)
dmax=max(d.values())
ans=[]
for i in d.keys():
    if d[i]==dmax:
        ans.append(i)

ans=sorted(ans)
for i in range(len(ans)):
    print(ans[i])


Measured memory_bytes: 116560
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1<<30;
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; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> const&P){
    os << P.first;
    os << " ";
    os << P.second;
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
//fixed<<setprecision(10)<<ans<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vi A(N);
    REP(i,N) cin >> A[i];

    int ans=inf;
    for(int i=-100;i<=100;i++){
        int res = 0;
        for(auto a:A) res+=abs(i-a)*abs(i-a);
        chmin(ans, res);
    }

    cout << ans << endl;
}

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


int main() {
  int diff;
  int point_Alice = 0;
  int point_Bob = 0;
  int N;
  cin >> N;
  vector<int> card(N);
  for (int i = 0; i < N; i++) {
    cin >> card.at(i);
  }
  
  for (int i = 0; i < N - 1; i++) {
    for (int j = N - 1; j > i; j--) {
      if (card.at(j) > card.at(j - 1)) {
        int k = card.at(j);
        card.at(j) = card.at(j - 1);
        card.at(j - 1) = k;
      }
    }
  }
  
  int i = 0;
  while (2 * i < N) {
    point_Alice += card.at(2 * i);
    i++;
  }
  i = 0;
  while (2 * i + 1 < N) {
    point_Bob += card.at(2 * i + 1);
    i++;
  }
  diff = point_Alice - point_Bob;
  cout << diff << endl;  
}


Measured memory_bytes: 256
N = int(input())
S = []
T = []
for _ in range(N):
    s, t = [s for s in input().split()]
    t = int(t)
    S.append(s)
    T.append(t)
X = input()
for i, s in enumerate(S):
    if s == X:
        print(sum(T[i+1:]))


Measured memory_bytes: 38256
#include<stdio.h>

long long max(long long x,long long y){
	if(x>y)return x;
	return y;
}

int main(){
	int N;
	scanf("%d",&N);
	long long a[N],b[N],c[N];
	for(int i=0;i<N;i++)scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
	
	long long sa[N],sb[N],sc[N];
	sa[0]=a[0];
	sb[0]=b[0];
	sc[0]=c[0];
	for(int i=1;i<N;i++)sa[i]=sb[i]=sc[i]=0;
	
	for(int i=0;i+1<N;i++){
		sa[i+1]=max(sb[i],sc[i])+a[i+1];
		sb[i+1]=max(sc[i],sa[i])+b[i+1];
		sc[i+1]=max(sa[i],sb[i])+c[i+1];
	}
	
	long long ans=max(max(sa[N-1],sb[N-1]),sc[N-1]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4864
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using namespace std;
//LLONG_MAX = 90^18
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }
//max_element


signed main()
{
	int A, B, C, K;
	cin >> A >> B >> C >> K;

	int a =  max(0LL, min(K, A));
	int b = max(0LL, min(K - a, B));
	int c = max(0LL, min(K - a - b, C));

	cout << a - c << endl;
}




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

typedef long long ll;
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;

int main(){

    int n  ;
    string s;
    cin >>  n >> s;
    
    
    int ans = 0; 
    for(int i = 0;i<s.size();i++){
        int data[26];
        REP(k,26)data[k] = 0;
        for(int j = 0;j<i;j++){
            data[s[j] - 'a'] = 1;
        }
        for(int j = i;j<s.size();j++){
            if(data[s[j] - 'a'] == 1)data[s[j] - 'a']=2 ;
        }
        int a = 0;
        REP(f,26){
            if(data[f] == 2)a++;
        }
        ans = max(ans,a);
      	if(a == 10)cerr << i;
    }

    cout <<  ans ;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define rep(i,a,b) for (int i=(a); i<(b); i++)
#define per(i,a,b) for (int i=(b-1); i>=(a); i--)
#define debug(x) cout << #x << " => " << x << endl
using namespace std;

#define fi first
#define se second
#define mp make_pair
typedef pair<int,int> pii;

#define pb push_back
typedef vector<int> vi;

typedef long long ll;
typedef long double ld;

const int MAX_N = 7 + 500000;
///----------------------------------------------
char str[MAX_N];
int pre1[MAX_N], f1[MAX_N];
int pre2[MAX_N], f2[MAX_N];
int main() {

	///read
	scanf(" %s", str); int len=strlen(str);

	///work
	int now=-1; pre1[0]=-1;
	rep(i,1,len) {
		for (; ~now && str[now+1]!=str[i]; ) now=pre1[now];
		pre1[i] = (now += str[now+1]==str[i]);
	}
	now=len; pre2[len-1]=len;
	per(i,0,len-1) {
		for (; now<len && str[now-1]!=str[i]; ) now=pre2[now];
		pre2[i] = (now -= str[now-1]==str[i]);
	}
	
	
	///check
	rep(i,0,len) {
		if (pre1[i]==-1) f1[i]=i+1; else {
			if (i-pre1[i] == f1[pre1[i]]) {
				f1[i] = f1[pre1[i]];
			}
			else {
				f1[i] = i+1;
			}
		}
		//debug(f1[i]);
	}
	per(i,0,len) {
		if (pre2[i]==len) f2[i]=len-i; else {
			if (pre2[i]-i == f2[pre2[i]]) {
				f2[i] = f2[pre2[i]];
			}
			else {
				f2[i] = len-i;
			}
		}
		//debug(f2[i]);
	}

	///work
	if (f1[len-1]==len) {
		cout << 1 << endl << 1;
		return 0;
	}
	if (f1[len-1]==1) {
		cout << len << endl << 1;
		return 0;
	}
	int ans=0;
	rep(i,0,len-1) if (f1[i]==i+1 && f2[i+1]==len-i-1) ans++;
	cout << 2 << endl << ans;
	

}


Measured memory_bytes: 8576
N,T = map(int, input().split())
CT = [list(map(int, input().split())) for _ in range(N)]

min_c = 1001

for i in range(N):
    if CT[i][1] <= T:
        min_c = min(min_c, CT[i][0])

if min_c == 1001:
    print('TLE')
else:
    print(min_c)

Measured memory_bytes: 3064
<?php
fscanf(STDIN, rtrim("%d"), $n);
fscanf(STDIN, rtrim("%s"), $str);

$words = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");

for ($i=0; $i < strlen($str); $i++)
{ 
	reset($words);
	$j = 0;
	while($j < 26)
	{
		if(substr($str, $i, 1) == $words[$j])
		{
			echo($words[$j+$n]);
			break;
		}
		$j++;
	}
}

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

int main(){
  long n,m,inf = 1000000007;
  cin >> n >> m;
  vector<long> a(n);
  for(int i = 0;i < m;i++){
    cin >> a.at(i);
  }
  vector<long> result(n+1);
  result.at(0) = 1;
  int dangercount = 0;
  if(a.at(0) == 1){
    result.at(1) = 0;
    dangercount++;
  }
  else{
    result.at(1) = 1;
  }
  for(int i = 2;i <= n;i++){
    if(a.at(dangercount) == i){
      result.at(i) = 0;
      dangercount++;
    }
    else{
      result.at(i) = (result.at(i-1) + result.at(i-2)) % inf;
    }
  }
  cout << result.at(n) << endl;
}

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

int const MAX = 100005;
long long tree[MAX];

struct nbd {
	int number; long long length;
};
vector<nbd> graph[MAX];
long long dist[MAX];

int main() {
	int n;
	cin >> n;
	for (int i = 1; i<n; i++) {
		int a, b;
		long long c;
		cin >> a >> b >> c;
		nbd n1, n2;
		n1.number = b; n1.length = c;
		n2.number = a; n2.length = c;
		graph[a].push_back(n1);
		graph[b].push_back(n2);
	}
	int m, k;
	for (int i = 1; i <= n; i++) {
		dist[i] = -1;
	}
	cin >> m >> k;
	queue<int> q;
	q.push(k);
	dist[k] = 0;
	while (!q.empty()) {
		int now;
		now = q.front();
		q.pop();
		for (int i = 0; i<graph[now].size(); i++) {
			nbd next;
			next = graph[now][i];
			if (dist[next.number] == -1) {
				dist[next.number] = dist[now] + next.length;
				q.push(next.number);
			}
			
		}
	}
	for (int i = 0; i<m; i++) {
		int x, y;
		cin >> x >> y;
		cout << dist[x] + dist[y] << endl;
	}
}

Measured memory_bytes: 9984
a,b=map(int,input().split())
def ceil(x):
  if x%1==0:
    return x//1
  else:
    return x//1+1
a1=int(ceil(a*100/8))
a2=int(ceil((a+1)*100/8)-1)
b1=int(ceil(b*100/10))
b2=int(ceil((b+1)*100/10)-1)
count=0
for i in range(a1,a2+1):
  if b1<=i<=b2:
    print(i)
    count=0
    break
  else:
    count+=1
if count!=0:
  print(-1)

Measured memory_bytes: 3064
#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define NL << endl

using namespace std;
using ll = long long;
const int INTMAX = numeric_limits<int>::max();
const int INTMIN = numeric_limits<int>::min();
const ll LLMAX = numeric_limits<long long>::max();
const ll LLMIN = numeric_limits<long long>::min();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

using namespace std;

signed main() {
	int a, b, c;

	cin >> a >> b >> c;

	cout << min(b / a, c) << endl;


	return 0;
}



Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
count = 0

for i in range(n):
    minij =i
    for j in range(i,n):
        if a[j] < a[minij]:
            minij = j
    if a[i] > a[minij]:
        count+=1
        a[i],a[minij] = a[minij],a[i]

print(' '.join(map(str,a)))
print(count)



Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,cnt,ans=1e8;
ll a;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for (int i=0;i<n;++i)
	{
		cin>>a;
		cnt=0;
		while (a%2==0) ++cnt,a/=2;
		ans=min(ans,cnt);
	}
	cout<<ans;
	return 0;
}

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

#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPS(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

const ll INF = 1e18;
const ll MOD = 1e9+7;

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


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ll N; cin >> N;
    vl A(N); REP(i, N) cin >> A[i];
    vl B(N), C(N);
    REP(i, N)
    {
        B[i] = A[i]+i;
        C[i] = i - A[i];
    }
    sort(ALL(C));
    ll ans = 0;
    REP(i, N)
    {
        ans += upper_bound(ALL(C), B[i]) - lower_bound(ALL(C), B[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 7952
def main():
    N = int(input())

    def recur(s):
        if int(s) > N:
            return 0
        ret = 1 if all(s.count(c) for c in '753') else 0
        for c in '753':
            ret += recur(s + c)
        return ret
    print(recur('0'))


if __name__ == '__main__':
    main()


Measured memory_bytes: 55132
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int MOD = 1e9 + 7;
const int MAXN = 64;
const int MAXM = 128;
int poww[MAXM], dp[MAXM][MAXM];
inline int qpow(lint x, lint y) {
	lint res = 1;
	while (y) {
		if (y & 1) res = res * x % MOD;
		x = x * x % MOD, y >>= 1;
	}
	return res;
}
stack<int> sta;
vector<int> edge[MAXN];
vector<vector<int> > cyc;
int dfn[MAXN], low[MAXN];
inline void tarjan(int u, int par) {
	static int cnt = 0;
	dfn[u] = low[u]	= ++cnt;
	sta.push(u);
	for (auto v : edge[u]) if (v != par) {
		if (dfn[v]) {
			low[u] = min(low[u], dfn[v]);
		} else {
			tarjan(v, u);
			low[u] = min(low[u], low[v]);
			if (low[v] >= dfn[u]) {
				cyc.pb({u});
				while (sta.top() != v) {
					cyc.back().pb(sta.top());
					sta.pop();
				}	cyc.back().pb(sta.top());
					sta.pop();
			} 
		}
	}
}
inline int count(vector<int> & point) {
	static int Hash[MAXN];
	memset(Hash, 0, sizeof(Hash));
	for (auto p : point) {
		Hash[p] = 1;
	}
	int res = 0; 
	for (auto u : point) {
		for (auto v : edge[u]) {
			res += Hash[v];
		}
	}
	return res >> 1;
}
inline int polya(int n) {
	lint res = 0;
	rep (i, 1, n) {
		res += poww[__gcd(i, n)];
	}
	res %= MOD;
	res = res * qpow(n, MOD - 2) % MOD;
	return res;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int n, m, k;
	cin >> n >> m >> k;
	rep (i, 1, m) {
		int u, v;
		cin >> u >> v; 
		edge[u].pb(v);
		edge[v].pb(u);
	}
	poww[0] = 1;
	rep (i, 1, m) {
		poww[i] = poww[i - 1] * 1ll * k % MOD;
	}
	dp[0][0] = 1;
	rep (i, 1, k) {
		rep (j, 0, m) {
			rep (_j, 0, j) {
				dp[i][j] += dp[i - 1][_j];
				if (dp[i][j] >= MOD) dp[i][j] -= MOD;
			}
		}
	}
	rep (i, 1, n) {
		if (!dfn[i]) tarjan(i, 0);
	}
	lint ans = 1;
	for (auto & c : cyc) {
		int cnt = count(c);
		if (cnt == SZ(c)) {
			ans = ans * polya(cnt) % MOD;
		} else {
			ans = ans * dp[k][cnt] % MOD;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
N, K = map(int, input().split())
nums = list(map(int, input().split()))
expect = 0
answer = 0
for i in range(N):
  if i < K:
    expect += (nums[i]+1)/2
  else:
    expect += (nums[i]+1)/2 - (nums[i-K]+1)/2
  answer = max(answer, expect)
print(answer)

Measured memory_bytes: 99108
#include <iostream>
#include <algorithm>

using namespace std;

int calc(int x){
  int y=1;
  for(int i=0; i<x; i++) y*=10;
  return y;
}

int main(){
  int N, A;
  int a[10], n[10];
  int Anum=0;
  int Nnum=0;
  long long ans=0;
  cin >> N;
  int Ncopy=N;
  for(int i=0; N>0; i++){
    n[i]=N%10;
    N/=10;
    Nnum++;
  }
  for(int i=1; i<=Ncopy; i++){
    if(i%10==0) continue;
    A=i;
    Anum=0;
    for(int j=0; A>0; j++){
      a[j]=A%10;
      A/=10;
      Anum++;
    }
    if(a[0]==a[Anum-1]) ans++;
    if(Ncopy>=a[0]*10+a[Anum-1]) ans++;
    for(int k=3; k<Nnum; k++) ans+=calc(k-2);
    if(Nnum>=3){
      if(a[0]<n[Nnum-1]) ans+=calc(Nnum-2);
      if(a[0]==n[Nnum-1]){
        for(int l=0; l<calc(Nnum-2); l++){
          if(a[0]*calc(Nnum-1)+l*10+a[Anum-1]<=Ncopy) ans++;
        }
      }
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
import re
import sys


def main():
    s = sys.stdin.readline().rstrip().replace("?", ".")
    t = sys.stdin.readline().rstrip()

    n = len(s)
    m = len(t)
    ans = []

    for i in range(n - m + 1):
        if i == 0:
            tmp1 = ""
        else:
            tmp1 = s[:i]
        tmp2 = s[i : i + m]
        if i + m == n:
            tmp3 = ""
        else:
            tmp3 = s[i + m :]
        if re.fullmatch(tmp2, t):
            tmp2 = t
            tmp = tmp1 + tmp2 + tmp3
            ans.append(tmp)
    ans.sort()

    if ans:
        print(ans[0].replace(".", "a"))
    else:
        print("UNRESTORABLE")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    string S,T;cin>>S>>T;
    int LS=S.size();
    int LT=T.size();
    int ans=9999999;
    for(int i=0;i<=LS-LT;i++){
        int count=0;
        for(int j=0;j<LT;j++){
            if(S[i+j]!=T[j])count++;
        }
        ans=min(count,ans);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-9
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
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,B[10001];
	int ans=0;
	scan(N);
	rep(i,N-1){
		scan(B[i]);
	}
	B[N-1]=INF;
	rep(i,N){
		if(i>0) ans+=min(B[i-1],B[i]);
		else ans+=B[0];
	}
	prin(ans);
	return 0;
}


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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> dct;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define size(a) int(a.size())

const ll mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x,ll n,ll md){
    if(n==0)return 1;
    if(n%2==0)return modexp((x*x)%md,n/2,md);
    return (x*modexp((x*x)%md,n/2,md))%md;
}

bool compare(pll a,pll b){
    return a.first*b.second>a.second*b.first;
}

int main(){
    fastio;
    //clock_t tm = clock();
    ll n,d,z,x,h;
    cin>>n>>d>>z;
    vll c;
    f(i,0,n){
        cin>>x>>h;
        c.pb({x,h});
    }
    sort(all(c));
    vl a(n+1,0);
    ll ans=0,temp;
    int r=0;
    f(i,0,n){
        if(i>0)a[i]+=a[i-1];
        if(a[i]>=c[i].second)
            continue;
        x=c[i].second-a[i];
        temp=ceil((x*1.0)/z);
        ans+=temp;
        while(r<n and c[r].first<=c[i].first+2*d)
            ++r;
        a[r]-=temp*z;a[i]+=temp*z;
    }
    cout<<ans<<endl;
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}

Measured memory_bytes: 6000
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	long long a, b;
	cin >> a >> b;
	if (a == 0 || b == 0)puts("Zero");
	else if (a < 0 && 0 < b)puts("Zero");
	else if (a > 0 && b > 0)puts("Positive");
	else if (a < 0 && b < 0) {
		if ((b - a + 1) % 2 == 0)puts("Positive");
		else puts("Negative");
	}
	return 0;
}

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

using namespace std;

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

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

  // dp[i] := 残りの石がi個の状態で手番が回ってきたときの勝敗を表す bool 値
  vector<bool> dp(k + 1, false);
  // dp[0] = false;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j < n; j++) {
      if (i - a[j] < 0) {
        continue;
      }
      // 相手に負けの局面を押し付ける
      if (!dp[i - a[j]]) {
        dp[i] = true;
      }
    }
  }
  cout << (dp[k] ? "First" : "Second") << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;
int H,W;
char C[310][310];
bool used[310][310];
int table[310][310];
int dx[4] = {0,1,0,-1};
int dy[4] = {-1,0,1,0};

void dfs(int X,int tmp,int cnt){
    used[X][tmp] = 1;
    table[X][tmp] = cnt;
    REP(i,4){
        int x = X + dx[i];
        if(used[x][tmp]) continue;
        if(x < 0 || H <= x) continue;
        dfs(x,tmp,cnt);
    }
}

int DFS(int tmp,int Y){
    if(W <= Y+1) return INF;
    if(table[tmp][Y+1] == INF) return DFS(tmp,Y+1);
    else return table[tmp][Y+1];
}

int F(int tmp,int Y){
    if(Y - 1 < 0) return INF;
    if(table[tmp][Y-1] == INF) return F(tmp,Y-1);
    else return table[tmp][Y-1];
}

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    cin >> H >> W;int K;cin >> K;
    vector<pair<int,int>> V;
    REP(i,H) REP(j,W){
        table[i][j] = INF;
        cin >> C[i][j];
        if(C[i][j] == '#'){used[i][j] = 1;V.pb({i,j});}
    }
    REP(i,V.size()){
        table[V[i].first][V[i].second] = i;
        dfs(V[i].first,V[i].second,i);
    }
    REP(i,H) REP(j,W){
        if(table[i][j] == INF){
            table[i][j] = DFS(i,j);
        }
        if(table[i][j] == INF){
            table[i][j] = F(i,j);
        }
    }
    REP(i,H){
        REP(j,W){
            cout << table[i][j] + 1 << ' ';
        }
        cout << endl;
    }
}

Measured memory_bytes: 2164
def calc(n)
  (2**n) % 1000000007
end

n = gets.to_i
a = Array.new(n, 0)
gets.split.each do |x|
  a[x.to_i] += 1
end

if n.odd?
  a[0] += 1
  0.step(n - 1, 2) do |i|
    next if a[i] == 2
    puts 0
    exit
  end
else
  1.step(n - 1, 2) do |i|
    next if a[i] == 2
    puts 0
    exit
  end
end

puts calc(n / 2)

Measured memory_bytes: 8196
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;


int main() {
  ll sx,sy,tx,ty; cin >> sx >> sy >> tx >> ty;
  
  rep(i,ty-sy) cout << 'U';
  rep(i,tx-sx) cout << 'R';
  rep(i,ty-sy) cout << 'D';
  rep(i,tx-sx) cout << 'L';
  
  cout << 'L';
  rep(i,ty-sy+1) cout << 'U';
  rep(i,tx-sx+1) cout << 'R';
  cout << 'D';
  cout << 'R';
  rep(i,ty-sy+1) cout << 'D';
  rep(i,tx-sx+1) cout << 'L';
  cout << 'U' << endl;
}


Measured memory_bytes: 256
import sys
import math
N, K = map(int, sys.stdin.readline().rstrip().split())
A = list(map(int, sys.stdin.readline().rstrip().split()))
bin_k = bin(K)[2:].zfill(50)
cnt = [0] * 50

for a in A:
    bin_a = bin(a)[2:]
    for i, b in enumerate(bin_a[::-1]):
        if b == "1":
            cnt[i] += 1

cnt = cnt[::-1]

ans = 0
base = 2**(50 - 1)
flag = False
for i, c in enumerate(cnt):
    if flag:
        ans += base * max(c, N - c)
    else:
        if bin_k[i] == "1":
            if c >= N - c:
                ans += base * c
                flag = True
            else:
                ans += base * (N - c)

        else:
            ans += base * c
    base //= 2
print(ans)

Measured memory_bytes: 63628
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = S()
    print(n.count("2"))
    return


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


Measured memory_bytes: 39536
from typing import List


def main():
    n = int(input())
    m = xyz(n)
    for i in m:
        print(i)


def xyz(n: int) -> List[int]:
    result = [0] * n
    for x in range(1, 100):
        for y in range(1, 100):
            for z in range(1, 100):
                m = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
                if m > n:
                    break
                result[m - 1] += 1

    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 10388
using System;
using System.Collections.Generic;
class Program
{
    //static List<string> str = new List<string>();
	static void Main(string[] args)
	{
		// 入力フェーズ
		//int N = Int32.Parse(Console.ReadLine()); // 足場の数
		string[] frog = Console.ReadLine().Split(' '); // 足場の数とジャンプ力
		int N = Int32.Parse(frog[0]);
		int K = Int32.Parse	(frog[1]);
		string[] stone = Console.ReadLine().Split(' '); // 足場の高さ

		List<int> height = new List<int>();
		for(int i=0; i<N; i++){
			height.Add(Int32.Parse(stone[i]));
		}
//Console.WriteLine(height.Count + "");
		long[] dp = new long[N+1];

		dp[0] = 0; // 0番目まで到達するコスト = 0
		dp[1] = 0; // 1番目まで到達するコスト = 0
		dp[2] = Math.Abs(height[0] - height[1]); // 2番目まで到達するコスト
//Console.WriteLine(dp[2] + "");
		for(int i=3; i<=N; i++)
		{
			//long a = dp[i-1] + Math.Abs(height[i-2] - height[i-1]);
			//long b = dp[i-2] + Math.Abs(height[i-3] - height[i-1]);
			//Console.WriteLine(a + " " + b);
			// i+1番目まで到達する最小のコストをK通り調べる
			long minCost = dp[i-1] + Math.Abs(height[i-2] - height[i-1]); // i→i+1
			for(int j=1; j<K; j++)
			{
				if(i-2-j < 0)
					{
						break;
					}
				long cost = dp[i-1-j] + Math.Abs(height[i-2-j] - height[i-1]);
				if(minCost > cost)
					minCost = cost;
			}
			dp[i] = minCost;
		}
		Console.WriteLine(dp[N] + "");


    }

}


Measured memory_bytes: 20320
/*
      author  : nishi5451
      created : 15.08.2020 12:50:59
*/

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


int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    int ans = 0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            ans += d[i]*d[j];
        }   
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3580