akhauriyash/Code-Regression huggingface dataset:
/********************************************
 *Author*        :ZZZZone
 *Created Time*  : 日 10/22 19:52:17 2017
 * Ended  Time*  : 日 10/22 20:42:02 2017
*********************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
const int MaxN = 1e5;

char s[MaxN +5], t[MaxN + 5];
int tot;
int lens, lent;

inline void OPEN(string s){
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}

bool check(){
	int l = 1, r = lent;
	while(l < r){
		if(t[l] != t[r]) return false;
		l++, r--;
	}
	return true;
}

void solve(){
	int l = 1, r = lens;
	int cnt1 = 0, cnt2 = 0;
	int cnt = 0;
	while(l < r && cnt < 10){
		if(s[l] == 'x' && s[r] != 'x') cnt2++, l++;
		else if(s[l] != 'x' && s[r] == 'x') cnt1++, r--;
		else l++, r--;
	}
	printf("%d\n", cnt1 + cnt2);
}


int main()
{
	while(~scanf("%s", s + 1)){
		lens = strlen(s + 1); lent = 0;
		for(int i = 1; i <= lens; i++)
			if(s[i] != 'x') t[++lent] = s[i];
		if(check()) solve();
		else printf("-1\n");
	}
    return 0;
}


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


int main() 
{
	int B, C, D,E, X, K,N, M,i,j,k;
	int F;
	int A[3];
	cin >> A[0]>>A[1]>>A[2];
	sort(A, A + 3);
	if ((A[2] - (A[2] - A[1] + A[0])) % 2 == 0) {
		cout << A[2] - A[1] + (A[2] - (A[2] - A[1] + A[0])) / 2 << endl;
	}
	else {
		cout << A[2] - A[1] + (A[2] - (A[2] - A[1] + A[0])) /2 +2 << endl;
	}
    return 0;
}



Measured memory_bytes: 256
n,m=[int(x) for x in input().split()]
ac=[0]*n
wa=[0]*n
a=0
b=0
for i in range(m):
  P,s=input().split()
  p=int(P)-1
  if s=="AC":
    if ac[p]==0:
      ac[p]=1
      a+=1
      b+=wa[p]
  else:
    if ac[p]==0:
      wa[p]+=1
print(a,b)

Measured memory_bytes: 10380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i=0;i<(n);++i)
const ll MOD=1e9+7;
//const ll MOD=998244353;

template<typename T>
struct TreeDiameter{
    vector<T> dp;
    vector<vector<pair<int,T>>> G;
    TreeDiameter(int n):dp(n),G(n){}
    void add_edge(int u,int v,T c){
        G[u].emplace_back(v,c);
        G[v].emplace_back(u,c);
    }
    void dfs(int v,int p,int &s){
        if (p<0) dp[v]=T(0);
        if (dp[s]<dp[v]) s=v;
        for (auto e:G[v]){
            int u=e.first;
            if (u==p) continue;
            dp[u]=dp[v]+e.second;
            dfs(u,v,s);
        }
    }
    pair<int,int> endPoints(){
        int s=0;
        dfs(s,-1,s);
        int t=s;
        dfs(t,-1,t);
        return make_pair(s,t);
    }
    T build(){
        int t=endPoints().second;
        return dp[t];
    }
    vector<T> distance(int v){
        dfs(v,-1,v);
        return dp;
    }
    vector<T> farthest(){
        int t=endPoints().second;
        auto ds=dp;
        auto dt=distance(t);
        for (int i=0;i<ds.size();++i) chmax(ds[i],dt[i]);
        return ds;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    TreeDiameter<ll> TD(n);
    rep(i,n-1){
        int s,t; ll w; cin >> s >> t >> w;
        TD.add_edge(s,t,w);
    }
    cout << TD.build() << endl;
}

/* verify
    https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/5/GRL_5_B

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    TreeDiameter<int> TD(n);
    rep(i,n-1){
        int s,t,w; cin >> s >> t >> w;
        TD.add_edge(s,t,w);
    }
    vector<int> ans=TD.farthest();
    rep(i,n) cout << ans[i] << endl;
}
*/


Measured memory_bytes: 13744
#include "bits/stdc++.h"
using namespace std;

int main() {
  string C;
  string A;
     cin >> C;
  if(C == "a"||C == "i"|| C == "e"||C == "u"||C == "o"){
    A = "vowel";
  }else{
    A = "consonant";
  }
  cout << A;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define LL long long
#define INF (LL)(1LL<<60)

using namespace std;

void solve(long long H, long long W, long long N, std::vector<long long> a, std::vector<long long> b){
    vector<LL> ans(10, 0);
    map<pair<LL, LL>, LL> cnts;

    for(int i=0; i<N; i++){
        for(LL dx=-2; dx<=0; dx++){
            for(LL dy=-2; dy<=0; dy++){
                LL y=a[i]+dy, x=b[i]+dx;
                if(x<1||x>W-2||y<1||y>H-2)continue;
                cnts[make_pair(x, y)]++;
            }
        }
    }

    for(auto kv: cnts)ans[kv.second]++;

    ans[0]=(H-2)*(W-2)-accumulate(ans.begin()+1, ans.end(), 0LL);
    for(int i=0; i<10; i++)
        cout << ans[i] << endl;
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    std::vector<long long> b(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    solve(H, W, N, std::move(a), std::move(b));
    return 0;
}


Measured memory_bytes: 58112
#include <bits/stdc++.h>
using namespace std;
const int maxn=3e2+7;
int n,k,sum;
int path[maxn][maxn];
long long  dp[maxn][maxn],mp[maxn][maxn],ans[maxn];
int main()
{
    int l=0;
//    memset(dp,0x3f,sizeof(dp));
    scanf("%d",&n);
    for(int i=1; i<=n; ++i)
    {
        for(int j=1; j<=n; ++j)
        {
            scanf("%lld",&mp[i][j]);
            dp[i][j]=mp[i][j];
        }
    }
    for(int i=1; i<=n; ++i)
    {
        for(int u=1; u<=n; ++u)
        {
            for(int v=1; v<=n; ++v)
            {
                if(dp[u][v]>=mp[u][i]+mp[i][v]&&(i!=u)&&(i!=v))
                {
                    dp[u][v]=mp[u][i]+mp[i][v];
                    path[u][v]=1;
                }
            }
        }
    }
    bool flag=0;
    for(int u=1; u<=n; ++u)
    {
        for(int v=1; v<=n; ++v)
        {
            if(dp[u][v]!=mp[u][v])
            {
                flag=1;
                break;
            }
        }
    }
    if(flag)
        printf("-1\n");
    else
    {
        long long cnt=0;
        for(int i=1;i<=n;++i)
        {
            for(int j=i+1;j<=n;++j)
            {
                if(!path[i][j])
                    cnt=cnt+dp[i][j];
            }
        }
        printf("%lld\n",cnt);
    }
    return 0;
}
//3
//0 3 5
//3 0 1
//5 1 0



Measured memory_bytes: 2048
#include<iostream>
using namespace std;
int d,m=1e9+7,dp[10001][2][100];
string s;
main()
{
	cin>>s>>d;
	dp[0][0][0]=1;
	for(int i=0;i<s.size();i++)
	{
		for(int j=0;j<2;j++)
		{
			int L=j?9:s[i]-48;
			for(int l=0;l<=L;l++)
			{
				for(int k=0;k<d;k++)
					(dp[i+1][j|l<L][(k+l)%d]+=dp[i][j][k])%=m;
			}
		}
	}
	cout<<(dp[s.size()][0][0]+dp[s.size()][1][0]-1+m)%m<<endl;
}

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

int main(){
  int h,n;
  cin >> h >> n;
  vector<int> a(n);
  int s=0;
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    s+=a.at(i);
  }
  if(s<h){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}

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

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

    int cnt = 0;

    while(B <= A){
        B *= 2;
        cnt++;
    }
    while(C <= B){
        C *= 2;
        cnt++;
    }

    if (cnt <= K){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3644
"use strict";

var main = function main(input) {
  var N = input.split(' ')[0];
  var Y = input.split(' ')[1];
  var flag = false;

  for (var i = 0; i <= N; i++) {
    var Yminus1000 = Y - 1000 * i;

    for (var j = 0; j <= N - i; j++) {
      var Yminus1000minus5000 = Yminus1000 - 5000 * j;
      var k = Yminus1000minus5000 / 10000;

      if (Yminus1000minus5000 % 10000 == 0 && i + j + k == N) {
        console.log("".concat(k, " ").concat(j, " ").concat(i));
        flag = true;
        break;
      }
    }

    if (flag) {
      break;
    }
  }

  if (!flag) {
    console.log("-1 -1 -1");
  }
};

main(require('fs').readFileSync('/dev/stdin', 'utf-8'));

Measured memory_bytes: 9804
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        int max = 0;
        for (int i=1;i<N;i++){
            String strr = S.substring(0,i);
            String strl = S.substring(i);
            int count = 0;
            boolean[] b1 = new boolean[26];
            boolean[] b2 = new boolean[26];
            for (int j=0;j<strr.length();j++){
                b1[strr.charAt(j)-'a']=true;
            }
            for (int j=0;j<strl.length();j++){
                b2[strl.charAt(j)-'a']=true;
            }
            for (int j=0;j<26;j++){
                if (b1[j]&&b2[j]){
                  count++;
                }
            }
            max = Math.max(max,count);
        }
        System.out.println(max);
    }
}


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

LL N,A,B;
LL h[100010];
int main () {
	scanf("%lld%lld%lld",&N,&A,&B);

	for(int i = 1;i <= N;++i)
		scanf("%lld",&h[i]);
	LL l = 1,r = 1000000000;
	LL mid;

	while(l <= r) {
		mid = (l + r) >> 1;
		LL ans = 0;
        for(int i = 1;i <= N;++i) {
            if(h[i] - mid * B > 0)
				ans += (h[i] - mid * B) / (A - B) + ((h[i] - mid * B) % (A - B) != 0);
        }
        if(ans > mid)
            l = mid + 1;
        else r = mid - 1;
	}
	printf("%lld\n",r + 1);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

ll N, M;

void solve() {
	cin >> N >> M;
	if((N + M) % 2) cout << "IMPOSSIBLE\n";
	else cout << (N + M) / 2 << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()
cnt = [0] * (N + 1)

for i in range(N):
    cnt[i + 1] = cnt[i] + (1 if S[i:i + 2] == "AC" else 0)

for i in range(Q):
    l, r = map(int, input().split())
    print(cnt[r - 1] - cnt[l - 1])

Measured memory_bytes: 7748
import sys
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
flower = read_int()

ans = 0
def rec(l,r):
    minf = float('INF')
    for i in range(l,r):
        minf = min(minf, flower[i])

    # watering (reverse)
    zero_index = []
    for i in range(l,r):
        flower[i] -= minf
        if flower[i] == 0:
            zero_index.append(i)
    global ans
    ans += minf

    zero_index.append(r)
    zero_index.insert(0,l-1)
    for i in range(len(zero_index) - 1):
        if zero_index[i] + 1 != zero_index[i + 1]:
            rec(zero_index[i] + 1, zero_index[i + 1])


if __name__ == "__main__":
    rec(0, N)
    print(ans)

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

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vll;


int main() {
    ll n, k;
    cin >> n >> k;
    int cnt = 0;
    ll tmp = k;
    while (k > 0) {
        k /= 2;
        ++cnt;
    }
    vector<int> v(cnt);
    vll nums(n);
    for (int i = 0; i < n; ++i) {
        cin >> nums[i];
        ll mask = 1;
        for (int j = 0; j < cnt; ++j) {
            if (mask & nums[i]) {
                ++v[j];
            }
            mask <<= 1;
        }
    }
    ll mask = (1ll << (cnt - 1));
    bool enable = false;
    ll prev = tmp;
    for (int i = cnt - 1; i >= 0; --i) {
        if (v[i] > n - v[i]) {
            tmp = tmp & ~(mask);
            if (prev > tmp) {
                enable = true;
            }
            prev = tmp;
        } else {
            if (enable) {
                tmp = tmp | mask;
            }
        }
        mask >>= 1;
    }
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += (tmp ^ nums[i]);
    }
    cout << ans << endl;
    return 0;
}


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

const int MAX_N = 3010;
int N, T;
int dp1[MAX_N][MAX_N];
pair<int, int> AB[MAX_N];
int B[MAX_N]; // B[i] -- i+1~N番までで最大の満足度B 

int main()
{
    scanf("%d %d", &N, &T);
    REP(i, 0, N) scanf("%d %d", &AB[i].first, &AB[i].second);
    sort(AB, AB + N);

    REP(i, 0, N) REP(j, 0, T){
        dp1[i+1][j] = max(dp1[i+1][j], dp1[i][j]);
        int p = j + AB[i].first;
        if(p < T) dp1[i+1][p] = max(dp1[i+1][p], dp1[i][j] + AB[i].second);
    }
    B[N] = 0;
    for(int i = N-1; i > 0; --i) B[i] = max(AB[i].second, B[i+1]);
    int res = 0;
    REP(i, 1, N+1) REP(j, 0, T) res = max(res, dp1[i][j] + B[i]);
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 35584
N, Ma, Mb = map(int, input().split())

kusuri = []
cusum = [0]*(N+1)
for i in range(N):
  a, b, c = map(int, input().split())
  sa = a*Mb - b*Ma
  kusuri.append((sa, c))
  cusum[i+1] = cusum[i] + c

call = cusum[-1]
dp = [[call+1]*8001 for _ in range(41)]
dp[0][4000] = 0

cmin = call+1
for i, j in enumerate(kusuri):
  d = j[0]
  c = j[1]
  for k in range(4000-100*i, 4000+100*i+1):
    dp[i+1][k] = min(dp[i+1][k], dp[i][k])
    if k + d == 4000:
      cmin = min(cmin, dp[i][k]+c)
    dp[i+1][k+d] = min(dp[i+1][k+d], dp[i][k]+c)
    

if cmin == call+1:
  print(-1)
else:
  print(cmin)

Measured memory_bytes: 5872
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().execute();
	}
	
	private void execute() {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		int[] a = new int[N];
		long f = 0;
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			f += a[i] -1;
		}
		System.out.println(f);
		sc.close();
	}
	
}


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

int main(){
    int a,b;

    cin>>a>>b;
    
    if((a <= 0 && b >= 0 )|| (a == 0 || b == 0)){
        cout<<"Zero\n";
        return 0;
    }
    else if(a < 0 && (b - a + 1) % 2){
        cout<<"Negative\n";
        return 0;
    }

    cout<<"Positive\n";

}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)
syugo = [0]*N
syugo[0] = A[0]
syugo[1] = A[1]
flg = False
ans = A[0]
idx = 1
for i in range(2, N):
    if flg:
        ans += A[idx]
        flg = False
        idx += 1
    else:
        ans += A[idx]
        flg = True

print(ans)


Measured memory_bytes: 31572
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int n;
	cin>>n;
	
	set<string> st;
	REP(i,n){
		string s;
		cin>>s;
		
		st.insert(s);
	}
	
	cout<<st.size()<<endl;
}

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

int main() {
  int A, B, C;

  cin >> A;
  cin >> B;
  
  if (A < 10) {
    C = 100 * (10 - A);
    C =  C + B;
      cout << C;
  }
    else {
      cout << B;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

const int R_MAX = 100011;
int n, k, m, r;
int ans[R_MAX];

void add(int d) {
	ans[0] += 1 / d;
	int res = 1 % d;
	repa(i,1,r+10) {
		res *= 10;
		ans[i] += res / d;
		if(res % d == 0) break;
		res = res % d;
	}

	repd(i,r+10,0) {
		if(ans[i] >= 10) {
			int u = ans[i] / 10;
			ans[i] = ans[i] % 10;
			ans[i-1] += u;
		}
	}
}

void div(int d) {
	int res = 0;
	rep(i,r+10) {
		res += ans[i];
		ans[i] = res / d;
		res = res % d;
		res *= 10;
	}
}

int main() {
	while(cin>>n>>k>>m>>r, n|k|m|r) {
		memset(ans, 0, sizeof(int) * R_MAX);
		if(m == 0) {
			add(n);
		} else {
			repa(i,1,n-1) {
				add(i);
			}
			div(n);
			add(n);
		}

		printf("%d.", ans[0]);
		repa(i,1,r) printf("%d", ans[i]);
		printf("\n");
	}
}

Measured memory_bytes: 1544
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

ll a[1000001]={};
ll r=1000001;
ll x[1000001]={};
int main() {

	int s;

	cin>>s;
	a[1]=s;

	x[s]=1;
	for(int j=2; j<r+1; j++){
		if(a[j-1]%2==0)a[j]=a[j-1]/2;
		if(a[j-1]%2>0)a[j]=a[j-1]+a[j-1]+a[j-1]+1;
		if(x[a[j]]==1){
			cout<<j<<endl;
			return 0;
		}else{
			x[a[j]]=1;
		}
	}

	return 0;
}


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

int main(){
  int H,W;
  cin >> H >> W;
  char a[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> a[i][j];
    }
  }
  for(int i=0;i<=H+1;i++){
    if(i==0||i==H+1){
      for(int j=0;j<=W+1;j++)
      	cout << '#';
    }
    else{
    	for(int j=0;j<=W+1;j++){
          if(j==0||j==W+1)
      		cout << '#';
          else
            cout << a[i-1][j-1];
    	}
    }
    cout << endl;
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
struct edge{ll to,cost;};
const int inf = 1<<28;
const ll INF = 1LL<<53;
const int COMBMAX = 500005;
const ll MOD = 1e9+7;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;++i)
#define repf(i,n) for(int i=0;i<=n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define eachdo(v, e) for(const auto& e : v)
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (ll)distance(v.begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (ll)distance(v.begin(), upper_bound((v).begin(), (v).end(), e))
ll mpow(ll a, ll n,ll mod=MOD){ll res=1;while(n>0){if(n&1)res=res*a%mod;a=a*a%mod;n>>=1;}return res;}
template<class T1, class T2> ll bcount(T1 v, T2 a){return upper_index(v,a)-lower_index(v,a);} 
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
template<class T> void debug2(T v){rep(i,v.size()){rep(j,v[i].size())cout<<v[i][j]<<" ";cout<<endl;}}
template<class T> void rdv(T &v){rep(i,v.size())cin>>v[i];}
template<class T> void rdvv(T &v){rep(i,v.size()){rep(j,v[i].size())cin>>v[i][j];}}
// multimap
// mmap.emplace(key,value);
// auto ngw = list.equal_range("");
// for(auto e = ngw.first; it != ngw.second ; ++e)


int main(){
    ll N,A,B; cin>> N >> A >> B;
    vl h(N); rdv(h);

    ll l = 0, r = 10000000000;
    while(1<r-l){
        ll mid = (l+r)/2;
        ll bomb = 0;
        rep(i,N){
            if (h[i] - B * mid <= 0) continue;
            bomb += (h[i] - B * mid + (A - B - 1)) / (A - B);
        }
        if (bomb <= mid) r = mid;
        else l = mid;
        // cout << l << " " << r << endl;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;

int main(){
  long long int a,b;
  cin>>a>>b;
  if(a%b==0){
    cout<<-1<<endl;
    return 0;
  }

  for(int i=1;i<1e9;i++){
    if((a*i)%b!=0){
      cout<<a*i<<endl;
      return 0;
    }
  }
}


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

using namespace std;


int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if((a == b && a != c) || (b == c && b != a) || (c == a && c != b)){
        cout << "Yes";
    }else{
        cout << "No";
    }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef _IS_LOCAL //
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout   \
	if (false) \
	cout
#define debug() if (false)
#define dvout if(false) cout
#endif //
#define next asdnext
#define prev asdprev
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define vrep(i, v) for (auto &i : v)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力
#define vecin(v,n)	\
	vec(v,n);		\
	vin(v);
#define vec(v, n) vector<int> v(n, 0);
#define mod (int)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
void Main()
{
	int N;
	cin>>N;

	vecin(H,N);

	int now = -1;

	for(int i = 0; i < N; i++){
		if(H[i]<now){
			cout<<"No\n";
			return;
		}
		else{
			if(H[i]==now){
			}
			else{
				now = H[i]-1;
			}
		}
	}
	cout<<"Yes\n";
}
 
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();

		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else {
			System.out.println("a == b");
		}
	}

}

Measured memory_bytes: 26028
import sys

n, k = map(int, sys.stdin.readline().split())
s = sys.stdin.readline().rstrip()
s += '0'

def main():
    l = [0]
    r = [0]
    flag = False
    for i in range(n+1):
        if s[i] == '1':
            if not flag:
                l.append(i)
            flag = True
        else:
            if flag:
                r.append(i-1)
            flag = False

    l.append(n-1)
    r.append(n-1)
    m = len(l)

    if k >= m - 1:
        return n
    res = 0
    for i in range(m-k):
        res = max(res, r[i+k]-l[i]+1)
    return res
    
if __name__ == '__main__':
    ans = main()
    print(ans)

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

typedef long long ll;

int main(){
	static ll n,d;
	static ll a[500010];
	static ll loc[500010];
	scanf("%lld%lld",&n,&d);
	for(int i = 1 ; i <= n ; i ++){
		scanf("%lld",&a[i]);
	}
	loc[0] = d;
	for(int i = 1 ; i <= n ; i ++){
		loc[i] = min( loc[i-1] , abs(loc[i-1]-a[i]) );
	}
	
	static ll b[500010];
	b[n] = 0;
	for(int i = n ; i >= 1 ; i --){
		if(b[i] >= a[i]/2)b[i-1] = b[i]+a[i];
		else b[i-1] = b[i];
	}
	
	/*for(int i = 0 ; i <= n ; i ++){
		cout << loc[i] << " " ;
	}cout << endl;
	for(int i = 0 ; i <= n ; i ++){
		cout << b[i] << " " ;
	}cout << endl;*/
	
	ll Q;
	scanf("%lld",&Q);
	for(int i = 0 ; i < Q ; i ++){
		ll q;
		scanf("%lld",&q);
		if(loc[q-1] <= b[q])puts("NO");
		else puts("YES");
	}
}

Measured memory_bytes: 13696
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), a = sc.nextInt(),b=sc.nextInt();
		//int x=sc.nextInt();//,k=sc.nextInt();
		long sum=0,count=0,flag=0,max=-999999,min=99999;
		long[] array=new long[101];
		//String s=sc.next(),t=sc.next();
		String buff;
		//String[] arrays = new String[a];
		for(int i=1;i<=n;i++) {
			buff = String.valueOf(i);
			for(int j=0;j<buff.length();j++) {
				sum+=Integer.parseInt(buff.substring(j,j+1));
			}
			//System.out.println(sum);
			if(sum>=a&&sum<=b)count+=i;
			sum=0;
		}
		System.out.println(count);



	}
	public static int sample(int n) {
		return n;
	}

}


Measured memory_bytes: 24276
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int t[4] = {0}, n;
	char c;
	string s;
	while (1)
	{
		cin >> n;
		if (cin.eof()) break;
		cin >> c >> s;
		if (s == "A")	t[0]++;
		if (s == "B")	t[1]++;
		if (s == "AB")	t[2]++;
		if (s == "O")	t[3]++;
	}
	cout << t[0] << endl << t[1] << endl << t[2] << endl << t[3] << endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll h,w,n;
    cin >> h >> w >> n;
    vector<ll>a(n);
    for(ll i=0;i<n;i++) cin >> a[i];
    vector<vector<ll>>ans(h,vector<ll>(w));
    ll turn=0,x=0,y=0;
    for(ll i=0;i<n;i++){
        while(a[i]>0){
            if(y>=w){
                turn=1;
                y=w-1;
                x++;
            }
            if(y<0){
                turn=0;
                y=0;
                x++;
            }
            ans[x][y]=i+1;
            if(turn==0) y++;
            else y--;
            a[i]--;
        }
    }
    
    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 3748
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int wcount[n];
  fill(wcount, wcount + n, 0);
  if (s[0] == 'W') wcount[0] = 1;
  for (int i = 1; i < n; i++) {
    wcount[i] = wcount[i - 1];
    if (s[i] == 'W') wcount[i]++;
  }
  int ans = min(wcount[n - 1], n - wcount[n - 1]);
  for (int i = 1; i < n - 1; i++) {
    int res = wcount[i - 1] + (n - i - 1) -  (wcount[n - 1] - wcount[i]);
    ans = min(res, ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1796
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T>T& max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T& min(T&a,T&b){if(a<b)return a;return b;}
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;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

ll N;
ll A[2005];

ll dp[2010][2010][2]; // dp[??????][??????][?????????]

ll conv(int pos)
{
    if (pos < 0) return N - 1;
    if (pos >= N) return 0;
    return pos;
}

ll rec(ll l, ll r, bool turn)
{
    if (l == r) return A[l] * !turn;
    
    if (~dp[l][r][turn]) return dp[l][r][turn];

    ll res = 0;

    if (turn == false) { // JOI
        res = max(A[l] + rec(conv(l - 1), r, turn ^ 1), A[r] + rec(l, conv(r + 1), turn ^ 1));
    } else {
        if (A[l] > A[r]) {
            res = rec(conv(l - 1), r, turn ^ 1);
        } else {
            res = rec(l, conv(r + 1), turn ^ 1);
        }
    }

    return dp[l][r][turn] = res;
}

signed main()
{
    memset(dp, -1, sizeof(dp));
    cin >> N;

    rep(i, N) {
        cin >> A[i];
    }

    ll ma = 0;

    rep(i, N) {
        ma = max(ma, A[i] + rec(conv(i - 1), conv(i + 1), 1));
    }

    cout << ma << endl;
}

Measured memory_bytes: 64396
import sys

a = list(input())
b = list(input())

if len(a) != len(b):
    print('No')
    sys.exit(0)
transf = dict([])
used = set([])
for i in range(len(a)):
    if a[i] in transf.keys() and transf[a[i]] != b[i]:
        print('No')
        sys.exit(0)
    if a[i] not in transf.keys():
        if b[i] in used:
            print('No')
            sys.exit(0)
        else:
            used.add(b[i])
        transf[a[i]] = b[i]
        
print('Yes')


Measured memory_bytes: 6704
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        h: usize,
        w: usize,
        lines: [String; h],
    }
    for line in lines {
        println!("{}\n{}", line, line);
    }
} 


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)

int main() {
  int N,L,i,j;
  cin >> N >> L;
  vector<string> v(N);
  rep(i,N){
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  rep(i,N){
    cout << v[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for i in range(N):
    if B[i] < A[i]:
        ans += B[i]
    elif A[i] <= B[i] <= A[i] + A[i+1]:
        ans += B[i]
        A[i+1] -= B[i] - A[i]
    else:
        ans += A[i] + A[i+1]
        A[i] = 0
        A[i+1] = 0

print(ans)

Measured memory_bytes: 18624
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

bool check(string S) {
    string R = S;
    reverse(S.begin(), S.end());
    for (int i = 0; i < S.length()/2; i++) {
        if (S[i] != R[i]) return false;
    }
    return true;
}

int main()
{
    string S; cin >> S;
    int N = (int) S.length();

    string S_first = S.substr(0, (N-1)/2);
    string S_second = S.substr((N+3)/2-1, N);

    if (check(S) && check(S_first) && check(S_second)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

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

  int sum = 0;
  for (int i = 0; i < (int)n.size(); i++) {
    int num = n.at(i) - '0';
    sum += num;
  }

  if (sum % 9 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3720
#include<iostream>
#include<map>
#include<set>
using namespace std;

int main(){
    long long N;
    cin >> N;
    long long A[N+1];
    long long i;
    map<long long, long long> m;
    map<long long, long long>::iterator pm;
    set<long long> s;
    long long sizepast = 0;
    for(i = 1; i <= N; i++){
        cin >> A[i];
        s.insert(A[i]);
        if(sizepast + 1 == s.size()){
            sizepast++;
            m.insert(pair<long long, long long>(A[i],1));
        }else{
            m[A[i]] = m[A[i]] + 1;
        }
    }
    long long sum = 0;
    long long r;
    for(pm = m.begin(); pm != m.end(); ++pm){
        r = pm->second;
        sum = sum + (r*(r-1))/2;
    }
    for(i = 1; i <= N; i++){
        cout << sum - (m[A[i]]-1) << endl;
    }
    
    system("pause");
    return 0;
}

Measured memory_bytes: 17272
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int n;
int dp[3][111];
vector<vi> a;

int solve(int x, int y)
{
	if (dp[x][y] >= 0) return dp[x][y];
	if (x == 1 && y == n - 1) return a[x][y];
	int res = -1;
	if (x == 1) res = solve(x, y + 1) + a[x][y];
	else if (y == n - 1) res = solve(x + 1, y) + a[x][y];
	else res = max(solve(x, y + 1), solve(x + 1, y)) + a[x][y];
	return dp[x][y] = res;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	MS(dp, -1);
	cin >> n;
	a.resize(2, vi(n));
	cin >> a;
	cout << solve(0, 0) << endl;
	return 0;
}

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

struct Ps{
  int r,c;
  Ps():r(0),c(0){}
  Ps(int r,int c):r(r),c(c){}
  Ps operator+(const Ps&p)const
  { return Ps(r+p.r,c+p.c);  }
  friend istream& operator>>(istream&is,Ps&p)
  {is >> p.r >> p.c; return is;  }
};

int main(){
  int h,w; cin >> h >> w;
  Ps s,g; cin >> s >> g;
  s = s+Ps(-1,-1);
  g = g+Ps(-1,-1);
  bitset<1000> mz[1000];
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      char c; cin >> c;
      mz[i][j] = c == '.';
    }
  }
  optional<int> distance[1000][1000];
  deque<pair<Ps,int>> dq;
  dq.emplace_front(s,0);
  while(!dq.empty()){
    auto [ps,di] = dq.front();
    dq.pop_front();
    if(distance[ps.r][ps.c])continue;
    distance[ps.r][ps.c] = di;
    static int mr[] = {0,0,1,-1};
    static int mc[] = {1,-1,0,0};
    for(int i = 0; i < 4; ++i){
      Ps nps = ps + Ps(mr[i],mc[i]);
      if(nps.r < 0 || nps.c < 0 || nps.r >= h || nps.c >= w)continue;
      if(!mz[nps.r][nps.c])continue;
      if(distance[nps.r][nps.c])continue;
      dq.emplace_front(nps,di);      
    }
    for(int i = -2; i <= 2; ++i){
      for(int j = -2; j <= 2; ++j){
	Ps nps = ps + Ps(i,j);

	if(nps.r < 0 || nps.c < 0 || nps.r >= h || nps.c >= w)continue;
	if(!mz[nps.r][nps.c])continue;
	if(distance[nps.r][nps.c])continue;
	dq.emplace_back(nps,di+1);
      }
    }
  }
  cout << (distance[g.r][g.c] ? distance[g.r][g.c].value() : -1) << endl;
}


Measured memory_bytes: 11904
#include<stdio.h>

int main(void) {
	int N,i,j;
	double v[1000],sum=0.0,box;
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%lf",&v[i]);
	}
	for (i = 0; i < N-1; i++) {
		for(j=i+1;j<N;j++)
			if (v[i] > v[j]) {
				box = v[i];
				v[i] = v[j];
				v[j] = box;
			}
	}
	sum = (v[0] + v[1]) / 2;
	for (i = 2; i < N; i++) {
		sum = (sum + v[i]) / 2;
	}
    printf("%f",sum);

	return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> a(M), b(M), c(M);
    REP(i, M)
    {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
        c[i] = -c[i];
    }

    vector<ll> dist(N);
    const ll INF = 1ll << 50;
    dist[0] = 0;
    REP(i, N - 1) dist[i + 1] = INF;
    REP(i, N - 1)
    {
        REP(j, M)
        {
            if (dist[a[j]] == INF) continue;
            dist[b[j]] = min(dist[b[j]], dist[a[j]] + c[j]);
        }
    }
    ll ans = -dist[N - 1];

    vector<bool> update(N, false);
    REP(i, N)
    {
        REP(j, M)
        {
            if (dist[a[j]] == INF) continue;
            if (dist[b[j]] > dist[a[j]] + c[j])
            {
                dist[b[j]] = dist[a[j]] + c[j];
                update[b[j]] = true;
            }
            if (update[a[j]]) update[b[j]] = true;
        }
    }
    
    if (update[N - 1])
    {
        cout << "inf" << endl;
    }
    else
    {
        cout << ans << endl;
    }
    
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<time.h>
#include<list>
#include<iomanip>
#include<cstring>
#define h 100
#define s 10010
#define ll long long
#define pb push_back
using namespace std;
int main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll int i, j, k, l;
  vector<int>a(s,0);
  for(i=1;i<=h;i++) 
  {
    for(j=1;j<=h;j++) 
    for(k=1;k<=h;k++) 
   {
   	 l=(i*i)+(j*j)+(k*k)+(i*j)+(i*k)+(j*k);
   	 if(l<s) 
   	 a[l]+=1;
   } 
 } 
   cin>>i;
   for(j=1;j<=i;j++) 
   cout<<a[j]<<endl;
  return 0;
} 


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

using namespace std;

int main() {
  int n,m;
  cin >> n >> m;
  long long ans=0;
  priority_queue<int> que;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    que.push(a.at(i));
    ans += a.at(i);
  }
  long long dis=0;
  int x,k=0;
  while(k<m){
    dis += (que.top() + 1)/2;
    x = que.top()/2;
    que.push(x);
    que.pop();
    k++;
  }
  cout << ans - dis << endl;
  
  return 0;
}


Measured memory_bytes: 1276
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <time.h>
#include <iostream>
#include <vector>
#include <map>

using namespace std;
int main(void)
{

  int a = 1;
  long long int n, d, dd, b, c, K, count = 0, com = 0;
  cin >> n;

  vector<long long int> vec(n + 1, 0);
  map<long long int, long long int> m;

  cin >> K;
  for (long long int i = 1; i <= n; i++)
  {
    cin >> m[i];
  }

  d = 1;
  for (long long int j = 1; j <= K; j++)
  {
    d = m[d];
    vec[d]++;
    if (a == 1)
    {
      if (vec[d] == 2)
      {
        dd = d;
        a = 2;
        if (j == K)
        {
          cout << d << endl;
          return 0;
        }
        continue;
      }
      if (j == K)
      {
        cout << d << endl;
        return 0;
      }
    }
    if (a == 2)
    {
      com++;
      if (j == K)
      {
        cout << d << endl;
        return 0;
      }
      if (dd == d)
      {
        c = ((K - j) % com);
        for (int o = 0; o < c; o++)
        {
          d = m[d];
        }

        cout << d << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 17128
#include <limits>
using ll          = long long;
constexpr int INF = std::numeric_limits<int>::max() / 2;
constexpr ll LNF  = std::numeric_limits<ll>::max() / 2;

#ifndef DEBUG_HPP_OB5Y82L9
#define DEBUG_HPP_OB5Y82L9

#ifdef PA_DEBUG
#define PD(stmt) stmt
#else
#define PD(stmt)
#endif

#endif /* end of include guard: DEBUG_HPP_OB5Y82L9 */

#ifndef STREAM_HELPER_HPP_DNIKPKZJ
#define STREAM_HELPER_HPP_DNIKPKZJ

#include <iostream>
#include <vector>
namespace pcl { namespace utility {
    // useful for debug printing
    template <typename T>
    std::ostream &operator<<(std::ostream &os, std::vector<T> const &v) {
        for (size_t i = 0; i < v.size(); i++) {
            if (i != 0) os << ", ";
            os << v[i];
        }
        os << std::endl;
        return os;
    }

    template <typename T>
    std::ostream &operator<<(std::ostream &os,
                             std::vector<std::vector<T>> const &v) {
        for (auto const &x : v) os << x;
        return os;
    }

    // useful for getting input
    template <typename T>
    std::istream &operator>>(std::istream &is, std::vector<T> &v) {
        for (size_t i = 0; i < v.size(); i++) is >> v[i];
        return is;
    }

    // useful for getting input
    template <typename T>
    std::istream &operator>>(std::istream &is,
                             std::vector<std::vector<T>> &v) {
        for (size_t i = 0; i < v.size(); i++) is >> v[i];
        return is;
    }
}} // namespace pcl::utility

#endif /* end of include guard: STREAM_HELPER_HPP_DNIKPKZJ */


using namespace pcl::utility;

#include <bits/stdc++.h>
using namespace std;

template <typename T>
void print(vector<T> const &x, string s = "") {
    PD(cerr << s);
    PD(cerr << x);
}

ll compute(vector<ll> v, int K, int Q, vector<int> &seps) {
    int N = v.size();
    sort(seps.begin(), seps.end());
    seps.push_back(N);
    print(seps, "seps: ");
    for (int i = 1; i < (int)seps.size(); i++) {
        sort(v.begin() + seps[i - 1] + 1, v.begin() + seps[i]);
    }
    print(v, "sorted v: ");

    vector<ll> ans;
    ans.reserve(N);
    for (int i = 1; i < (int)seps.size(); i++) {
        ans.insert(ans.end(), v.begin() + seps[i - 1] + 1,
                   v.begin() + seps[i - 1] + 1 +
                       max(0, seps[i] - seps[i - 1] - 1 - K + 1));
    }
    print(ans, "ans: ");
    auto a = *min_element(ans.begin(), ans.end());
    nth_element(ans.begin(), ans.begin() + Q - 1, ans.end());
    seps.pop_back();
    return Q <= (int)ans.size() ? ans[Q - 1] - a : LNF;
}

int main() {
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<ll> orig(N);
    cin >> orig;

    vector<pair<ll, int>> cp(N);
    for (int i = 0; i < N; i++) {
        cp[i].first  = orig[i];
        cp[i].second = i;
    }
    sort(cp.begin(), cp.end());

    vector<int> seps = {-1};
    ll mi            = compute(orig, K, Q, seps);
    for (auto const &p : cp) {
        seps.push_back(p.second);
        ll res = compute(orig, K, Q, seps);
        if (res == LNF) break; // ??????
        mi = min(mi, res);
    }
    cout << mi << endl;
    return 0;
}


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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
        #define eprintf(...) 42
#endif

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

ll dp[100001][3];

int main()
{
  string s;
  cin >> s;
  int n = s.size();

  ll tmp = 1;
  rep(i, n){

    rep(j, 3){
      dp[i+1][j] += dp[i][j] * (s[i] == '?' ? 3: 1);
      dp[i+1][j] %= mod;
    }

    if(s[i] == 'A' or s[i] == '?'){
      dp[i+1][0] += tmp;
      dp[i+1][0] %= mod; 
    }

    if(s[i] == 'B' or s[i] == '?'){
      dp[i+1][1] += dp[i][0];
      dp[i+1][1] %= mod; 
    }

    if(s[i] == 'C' or s[i] == '?'){
      dp[i+1][2] += dp[i][1];
      dp[i+1][2] %= mod; 
    }

    if(s[i] == '?') tmp = tmp*3%mod;
  }

  cout << dp[n][2] << endl;

/*
  rep(i, n+1){
    rep(j, 3){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
*/

  return 0;
}


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

using namespace std;

int n,ans,a,k;

int sg(int n,int k)
{
	if (n<k) return 0;
	if (n%k==0) return n/k;
	int t=n/k+1,p=(n-(n/k)*k+t-1)/t;
	return sg(n-t*p,k);
}

int main()
{
	scanf("%d",&n);
	for (;n--;)
	{
		scanf("%d%d",&a,&k);
		ans^=sg(a,k);
	}
	if (ans) printf("Takahashi\n");else printf("Aoki\n");
	return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
res = ['']
(1..n).each do |i|
  x = i
  if x % 3 == 0
    res << i
  else
    while x > 0
      if x % 10 == 3
        res << i
        break
      end
      x /= 10
    end
  end
end
print res.join(' '), "\n"

Measured memory_bytes: 6168
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <string>
#include <iostream>
#include <complex>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <stack>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <random>
#include <set>
#include <vector>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#include <array>
#include <forward_list>
//#include <chrono>
#include <iomanip>
#include <utility>
#include <assert.h>

#pragma GCC optimize("Ofast")
#pragma target("sse", "sse1")

#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

mt19937 gen(34);

int n;
const ll MOD = 1e9 + 7;
ll a[300000], cnt[60];

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//	freopen("memory.in", "r", stdin);
	//	freopen("memory.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		for (int j = 0; j < 60; j++)
			cnt[j] += ((a[i] & (1ll << j)) != 0);
	}
	ll ans = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 60; j++)
			cnt[j] -= ((a[i] & (1ll << j)) != 0);
		ll ost = n - 1 - i;
		for (int j = 0; j < 60; j++)
		{
			ll res = (1ll << j) % MOD;
			if (a[i] & (1ll << j))
			{
				res *= (ost - cnt[j]);
				ans += res;
			}
			else
			{
				res *= cnt[j];
				ans += res;
			}
			ans %= MOD;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#define endl '\n'
using namespace std;

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

    int N, K, total=0;
    cin >> N >> K;
    int *p = new int[N];
    for(int i=0; i<N; i++){
        cin >> p[i];
    }
    sort(p, p + N);
    for(int i=0; i<K; i++){
        total += p[i];
    }
    cout << total;
    return 0;
}



Measured memory_bytes: 3660