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

int main() {
    int N = 3,n,i=0;
    vector<int> nums(N);
    for(i=0; i < N; i++){
        cin >> nums.at(i);
    }
    sort(nums.begin(),nums.end());
    for(i = 0; i < N -1; i++){
        cout << nums.at(i) << " ";
    }
    cout << nums.at(nums.size() -1) << endl;
}


Measured memory_bytes: 3108
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int MAX_N = 100100;
int N, M;
vector<int> A;
ll total;
ll imos[3 * MAX_N];
ll imos1[3 * MAX_N];
int main() {
  cin >> N >> M;
  A.resize(N);
  for (auto &val : A) {
    cin >> val;
    val--;
  }
  for (int i = 0; i < N - 1; i++) {
    int s = A[i];
    int t = A[i + 1];
    if (s > t) {
      t += M;
    }
    total += t - s;
    if (t - s > 1) {
      imos[s + 2] += 1;
      imos[t + 1] -= 1;

      imos1[t + 1] -= (t - s - 1);
    }
  }

  for (int i = 1; i < 2 * M; i++) {
    imos[i] += imos[i - 1];
    imos1[i] += imos1[i - 1] + imos[i];
  }
  vector<ll> profits(M);
  for (int i = 0; i < M; i++) {
    profits[i] = imos1[i] + imos1[i + M];
  }
  ll res = *max_element(profits.begin(), profits.end());
  cout << total - res << endl;
  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}

int main(){
    int n;
    cin >> n;
    vi a(n+1), b(n);
    rep(i, n+1){
        cin >> a.at(i);
    }
    rep(i, n){
        cin >> b.at(i);
    }
    ll sum = 0;
    rep(i, n){
        if(b[i] > a[i]){
            b[i] = b[i] - a[i];
            sum += a[i];
            if(b[i] > a[i+1]){
                sum += a[i+1];
                a[i+1] = 0;
            }
            else {
                sum += b[i];
                a[i+1] = a[i+1] - b[i];
            }
        }
        else {
            sum += b[i];
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1024
//Breadth First Search (?????????) Algorithm
#include<iostream>
#include<queue>
#define WH 0
#define GR 1
#define BL 2
#define INF 2000000
void bfs(int);
void init(void);
int n, *color, **M, *d;
std::queue<int> Q;
int main(){
  std::cin>>n;
  color=new int[n], d=new int[n], M=new int*[n];
  for(int i=0, u, k;i<n;i++){
    M[i]=new int[n];
    color[i]=WH, d[i]=INF;
    for(int j=0;j<n;j++) M[i][j]=0;
    std::cin>>u>>k;
    for(int j=0, v;j<k;j++){
      std::cin>>v;
      M[u-1][v-1]=1;
    }
  }
  bfs(0);
  for(int i=0;i<n;i++) std::cout<<i+1<<" "<<(d[i]!=INF?d[i]:-1)<<std::endl;
  delete color;
  delete d;
  for(int i=0;i<n;i++) delete M[i];
  delete M;
  return 0;
}

void bfs(int s){
  color[s]=GR, d[s]=0;
  Q.push(s);
  while(!Q.empty()){
    int u=Q.front();
    Q.pop();
    for(int i=0;i<n;i++){
      if(M[u][i]&&color[i]==WH){
        color[i]=GR, d[i]=d[u]+1;
        Q.push(i);
      }
    }
    color[u]=BL;
  }
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int cnt[100005];
int main(){
    /// input
    int n,x;
    cin>>x>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    /// process
    for(int i=0;i<n;i++){
        cnt[a[i]] = 1;
    }
    int dis = 1e9;
    int ans = 1000;
    for(int i=0;i<=101;i++){
        int found = cnt[i];
        if(found==1)continue;
        int tmp = abs(x-i);
        if(tmp<dis){
            dis = tmp;
            ans = i;
        }
    }
    /// output
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
    int n,sum=0;
    scanf("%d",&n);
    int a[2][101],b[101]={0},i,j;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[0][i]);
    }
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[1][i]);
    }
    sum=sum+a[0][0]+a[1][n-1];
    for(i=0;i<n-1;i++)//From the ith to the second line
    {
        for(j=i;j<n-1;j++)
        {
            b[i]=b[i]+a[1][j];
        }
        for(j=0;j<i;j++)
        {
            b[i]=b[i]+a[0][j+1];
        }
    }
    sort(b,b+(n-1),cmp);
    sum=sum+b[0];
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
typedef pair<int,int> pp;

bool cmp( pp a , pp b){
	return a.second > b.second;
}

int main(){
	int a,b,n;
	vector<pp> hello;
	while(scanf("%d,%d",&a,&b) && a){
			hello.push_back(make_pair(a,b));
	}
	vector<int> rank(hello.size());
	sort(hello.begin(),hello.end(),cmp);
	int r = 0;
	int mi = (1<<21);
	for(int i=0;i<hello.size();i++){
		if(mi > hello[i].second){
			r++;
			mi = hello[i].second;
		}
		rank[hello[i].first-1] = r ;
				
	}
	
	while(cin >> n){
		cout << rank[n-1] << endl;
	}
}

Measured memory_bytes: 0
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0
code = 0

for i in range(n):
    a = list(map(int, input().split()))
    
    for j in range(m):
        code += a[j] * b[j]
    
    code += c
    if code > 0:
        ans += 1
    code = 0
        
print(ans)


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

using namespace std;

int main() {

  string line;
  cin >> line;

  char c[] = {'A', 'A', 'A'};

  for (int i=0; i<line.size(); ++i) {
    c[0] = c[1];
    c[1] = c[2];
    c[2] = line[i];

    if (c[2] == c[1]) {
      cout << i << ' ' << i+1 << endl;
      return 0;
    }
    if (c[2] == c[0]) {
      cout << i-1 << ' ' << i+1 << endl;
      return 0;
    }
  }

  cout << "-1 -1" << endl;

  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
 
int main() {
    ll a, b; cin >> a >> b;
    if ((a + b) % 2 == 0) cout << (a + b) / 2 << endl;
    else cout << "IMPOSSIBLE" << endl;
}

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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int flag = 1;
    while(1){
        c=c-b;
        a=a-d;
        if(c<=0){
            cout << "Yes" << "\n";
            break;
        }else if(c>0 && a<=0){
            cout << "No" << "\n";
            break; 
        }
    }
    return 0;
}

Measured memory_bytes: 3636
//////////////////////////////
// Author: whatisit
// Date: 2020-05-18 10:10 
//////////////////////////////
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5;
int n;
vector<string> v;

bool compare(string s1, string s2) {
	if (s1.size() == s2.size()) return (s1 < s2);
	return (s1.size() < s2.size());
}

void dfs(string s) {
	if (s.size() > 10) return;
	v.push_back(s);
	if (s.size() == 0) {
		for (int i = 1; i <= 9; ++i) {
			dfs(to_string(i));
		}
		return;
	}
	char ch = s[s.size() - 1];
	dfs(s+ch);
	if (ch == '0') {
		dfs(s+'1');
	} else if (ch == '9') {
		dfs(s+'8');
	} else {
		dfs(s+(char(ch+1)));
		dfs(s+(char(ch-1)));
	}
	return;
}

void solve() {
	cin >> n;
	dfs("");
	sort(v.begin(), v.end(), compare);
	cout << v[n];
}
// brute force
/*
bool lunlun(long long n) {
	string s = to_string(n);
	for (int i = 0; i < s.size()-1; ++i) 
		if (abs(s[i] - s[i+1]) > 1) 
			return false;
	return true;
}

void solve() {
	int n, count = 0;
	cin >> n;
	const long long biggest_lunlun = 3234566667;
	for (long long i = 1; i <= biggest_lunlun; ++i) {
		if (lunlun(i)) {
			++count;
			if (count == n) {
				cout << i;
				break;
			}
		}
	}
}
*/

int main() {
	//cin.tie(0); ios_base::sync_with_stdio(0);
	solve();
	return 0;
}

Measured memory_bytes: 11732
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int x=1;
while(x!=0){
int n;
cin >> n;
if(n==0)return 0;
int x,y,ans1=0,ans2=0;
for(int i=0;i<n;i++){
cin >> x >> y;
if(x>y)ans1+=(x+y);
else if(x<y)ans2+=(x+y);
else{
ans1+=x;
ans2+=y;
}
}
printf("%d %d\n",ans1,ans2);
}
return 0;
}

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

using namespace std ;

const int MAX = 1e5 + 10 ;

long long arr[3][MAX] ;
int sz[3] , idx[3] , cnt[3] ;
int x , y , a , b , c ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>x>>y>>sz[0]>>sz[1]>>sz[2] ;
	priority_queue< pair<long long , int> >q ;
	for(int i = 0 ; i <= 2 ; ++i)
	{
		vector<long long>v ;
		for(int j = 0 ; j < sz[i] ; ++j)
		{
			cin>>arr[i][j] ;
			v.push_back(arr[i][j]) ;
			q.push({arr[i][j] , -1 * i}) ;
		}
		sort(v.rbegin() , v.rend()) ;
		for(int j = 0 ; j < sz[i] ; ++j)
			arr[i][j] = v[j] ;
	}
	long long ans = 0 ;
	idx[0] = x-1 , idx[1] = y-1 ;
	cnt[0] = x , cnt[1] = y ;
	while(q.size() > 0)
	{
		pair<long long , int>p = q.top() ;
		q.pop() ;
		p.second *= -1 ;
		if(p.second <= 1 && cnt[p.second] > 0)
		{
			ans += p.first ;
			cnt[p.second]-- ;
		}
		else if(p.second == 2)
		{
			if(cnt[0] > 0 && cnt[1] > 0)
			{
				if(p.first > arr[0][idx[0]] || p.first > arr[1][idx[1]])
				{
					ans += p.first * 1ll ;
					if(arr[0][idx[0]] < arr[1][idx[1]])
						cnt[0]-- , idx[0]-- ;
					else
						cnt[1]-- , idx[1]-- ;
				}
			}
			else if(cnt[0] > 0)
			{
				if(p.first > arr[0][idx[0]])
				{
					ans += p.first * 1ll ;
					cnt[0]-- , idx[0]-- ;
				}
			}
			else if(cnt[1] > 0)
			{
				if(p.first > arr[1][idx[1]])
				{
					ans += p.first * 1ll ;
					cnt[1]-- , idx[1]-- ;
				}
			}
		}
	}
	return cout<<ans<<"\n" , 0 ; 
}		

Measured memory_bytes: 14164
#include <stdio.h>
#include <string.h>
#include <iostream>
#define Re register int
#define LL long long
#define mod int(1e9+7)

int N;
LL K,ans;

struct mat{
	LL d[55][55];
	mat(void) {memset(d,0,sizeof(d));}
	mat operator * (mat x)
	{
		mat ret;
		for (Re i=1; i<=N; ++i)
			for (Re j=1; j<=N; ++j)
				for (Re k=1; k<=N; ++k)
					(ret.d[i][j]+=this->d[i][k]*x.d[k][j])%=mod;
		return ret;
	}
	mat operator ^ (LL x)
	{
		mat base,ret;
		for (Re i=1; i<=N; ++i) ret.d[i][i]=1;
		memcpy(base.d,this->d,sizeof(this->d));
		while (x)
		{
			if (x&1) ret=ret*base;
			x>>=1; base=base*base;
		} return ret;
	}
}A;

template <typename T> inline void read(T &var)
{
	T x=0; int w=0; char ch=0;
	while (!isdigit(ch)) w|=ch=='-',ch=getchar();
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	var=w?-x:x;
}
int main(int argc, char const *argv[])
{
	read(N),read(K);
	for (Re i=1; i<=N; ++i)
		for (Re j=1; j<=N; ++j)
			read(A.d[i][j]);
	A=A^K;
	for (Re i=1; i<=N; ++i)
		for (Re j=1; j<=N; ++j)
			(ans+=A.d[i][j])%=mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int nn=205;
typedef long long ll;

void CountTriangles(vector <int> A){

    int n=A.size();

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

    int count = 0;

    for( int i = n-1; i >= 1; i--){
        int l = 0, r = i-1;
        while( l < r){
            if( A[l] + A[r] > A[i]){
                count += r - l ;
                r--;
            }
            else
                l++;
        }
    }
    cout<<count;
}
int main(){

    vector<int> A;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        A.push_back(x);
    }

    CountTriangles(A);

}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;
    if (A < 10 && B < 10)
    {
        cout << A * B << endl;
    }
    else
    {
        cout << "-1" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
let nmq = readLine()!.split(separator: " ").map { Int($0)! }
let (n, m, q) = (nmq[0], nmq[1], nmq[2])
var a = Array(repeating: 0, count: q)
var b = Array(repeating: 0, count: q)
var c = Array(repeating: 0, count: q)
var d = Array(repeating: 0, count: q)
for i in 0..<q {
  let abcd = readLine()!.split(separator: " ").map { Int($0)! }
  a[i] = abcd[0] - 1
  b[i] = abcd[1] - 1
  c[i] = abcd[2]
  d[i] = abcd[3]
}

func combinations<T: Collection>(_ collection: T, _ length: Int) -> [[T.Element]]? {
  let collection = Array(collection)
  let count = collection.count
  if count < length { return nil }
  var dict = [Int: [Int: [[T.Element]]]]()
  func r(_ index: Int, _ length: Int) -> [[T.Element]] {
    if let result = dict[index]?[length] { return result }
    if length == 0 || index + length > count { return [[]] }
    var result = [[T.Element]]()
    for i in index...(count-length) {
      result += r(i + 1, length - 1).map { [collection[i]] + $0 }
    }
    dict[index] = dict[index] ?? [Int: [[T.Element]]]()
    dict[index]?[length] = result
    return result
  }
  return r(0, length)
}

var result = Int()
combinations(1...m+n-1, n)?.forEach { preS in
  var counter = 0
  let s = preS.enumerated().map { (i, element) in element - i }
  for i in 0..<q where s[b[i]] - s[a[i]] == c[i] { counter += d[i] }
  if result < counter { result = counter }
}

print(result)


Measured memory_bytes: 41192
package main

import "fmt"

func main() {
	// Code for B - Varied
	var S string
	fmt.Scanf("%s", &S)

	flag := make(map[string]int, len(S))

	for i := 0; i < len(S); i++ {
		flag[string(S[i])]++
	}

	var flagAns int = 0
	for _, v := range flag {
		if v > 1 {
			flagAns = 1
		}
	}

	if flagAns == 1 {
		fmt.Println("no")
	} else {
		fmt.Println("yes")
	}
}


Measured memory_bytes: 1836
import java.util.*

var count = 0
var sum = 0.0

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    var n = sc.nextInt()
    val t = (1..n).map { Pair(sc.nextDouble(), sc.nextDouble()) }

    dfs(n, t, mutableSetOf<Int>(), 0.0, -1)

    println(sum / count)
}

fun dfs(n: Int, t: List<Pair<Double, Double>>, used: MutableSet<Int>, usedSum: Double, pre: Int) {
    if (used.size == n) {
        count++
        sum += usedSum
        return
    }

    repeat(n) {
        if (!used.contains(it)) {
            val next = mutableSetOf<Int>()
            next.addAll(used)
            next.add(it)
            var nextUsedSum = usedSum
            if (pre != -1) {
                nextUsedSum += Math.sqrt(Math.pow(t[pre].first - t[it].first, 2.0) + Math.pow(t[pre].second - t[it].second, 2.0))
            }
            dfs(n, t, next, nextUsedSum, it)
        }
    }
}


Measured memory_bytes: 56740
/*
author : seryu
title : ABC177D_"Friends"
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define mreps(i,j,n) for(int i = j; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }

//Union-Find tree
struct Union_find
{
    vector<ll> par;
    vector<ll> rank;
    vector<ll> siz;

    Union_find(ll n) : par(n), rank(n), siz(n)
    {
        for (ll i = 0; i < n; i++)
        {
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }
    ll root(ll x)
    {
        if (par[x] == x) return x;
        else return par[x] = root(par[x]);
    }
    ll size(ll x)
    {
        return siz[root(x)];
    }
    void unite(ll x, ll y)
    {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry)return;
        if (rank[rx] < rank[ry])swap(rx, ry);
        par[ry] = rx;
        siz[rx] += siz[ry];
        if (rank[rx] == rank[ry])rank[rx]++;
    }
    bool same(ll x, ll y)
    {
        return root(x) == root(y);
    }
};

void solve()
{
    int n, m;
    cin >> n >> m;
    Union_find uf(n);
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--;b--;
        uf.unite(a, b);
    }
    int ans = 0;
    rep(i, n)chmax(ans, int(uf.size(i)));
    cout << ans << endl;
    return;	
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 7936
// ABC075B - 

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

typedef unsigned long long int ull;
typedef long long int ll;

int main() {
	int H, W;
	cin >> H >> W;
	string S[H];
	for (int i = 0; i < H; i++) {
		cin >> S[i];
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			int t = 0;
			for (int x = -1; x <= 1; x++) {
				for (int y = -1; y <= 1; y++) {
					if ((0 <= j + x)&&(j + x < W)
					  &&(0 <= i + y)&&(i + y < H)
					  &&(S[i + y][j + x] == '#')) {
						++t;
					}
				}
			}
			if (S[i][j] != '#') {
				cout << t;
			} else {
				cout << '#';
			}
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
constexpr int mod = 1e9 + 7, two = (mod+1)/2;
int n, m, k;
ll fac[N], inv[N];
ll powmod(ll a,ll b) 
{
	a %= mod;
	ll ans = 1;
	while(b)
	{
		if(b&1) ans = ans*a%mod;
		a = a*a%mod;
		b >>= 1;
	}
	return ans;
}
void init(int n)
{
	fac[0] = 1;
	for(int i=1;i<=n;i++) fac[i] = fac[i-1]*i%mod;
	inv[n] = powmod(fac[n],mod-2);
	for(int i=n-1;i>=0;i--) inv[i] = inv[i+1]*(i+1)%mod;
}
ll comp(ll a,ll b)
{
	if(a<b||b<0||a<0) return 0;
	return fac[a]*inv[b]%mod*inv[a-b]%mod;
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	ll ans = 0;
 	cin >> n >> m >> k;
 	init(n*m);
 	for(int i=1; i<n; i++)
 	{
		ll cur = 1ll*(n-i)*(n-i+1)%mod*m%mod*two%mod*m%mod;
		cur = cur*comp(n*m-2, k-2)%mod;
		ans = (ans + cur)%mod;
 	}
 	for(int i=1; i<m; i++)
 	{
		ll cur = 1ll*(m-i)*(m-i+1)%mod*n%mod*two%mod*n%mod;
		cur = cur*comp(n*m-2, k-2)%mod;
		ans = (ans + cur)%mod;
 	}
 	ans = (ans + mod)%mod;
 	cout << ans;
	return 0;
}


Measured memory_bytes: 3328
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
  
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>
  
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define plus fsghsf
#define minus ytryr
  
using namespace std;
  
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
  
const int N = 200000 + 239;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const ld eps = 1e-12;
const double pi = atan2(0, -1);
const int ABC = 26;

ll dp[N][40];

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 10.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, T;
    cin >> n >> T;
    vector<pair<int, int> > a;
    vector<ll> zero;
    rep(i, 0, n) {
        int x, y;
        cin >> x >> y;
        if (x == 0) {
            zero.push_back(y + 1);
        } else {
            a.push_back({x, y});
        }
    }
    sort(a.begin(), a.end(), [](auto &p1, auto &p2) {
        ll v = 1LL * p1.fi * (p2.se + 1) - 1LL * p2.fi * (p1.se + 1);
        return v > 0;
    });
    zero.push_back(0);
    sort(zero.begin(), zero.end());
    rep(i, 1, sz(zero)) {
        zero[i] += zero[i - 1];
    }
    n = sz(a);
    rep(i, 0, n + 1) {
        rep(j, 0, 40) {
            dp[i][j] = big;
        }
    }
    dp[0][0] = 0;
    rep(i, 0, n) {
        rep(j, 0, 40) {
            if (dp[i][j] > T) {
                continue;
            }
            setmin(dp[i + 1][j], dp[i][j]);
            ll val = dp[i][j] + 1 + (dp[i][j] + 1) * a[i].fi + a[i].se;
            if (val <= T) {
                setmin(dp[i + 1][j + 1], val);
            }
        }
    }
    int ans = 0;
    rep(j, 0, 40) {
        if (dp[n][j] <= T) {
            int cnt = upper_bound(zero.begin(), zero.end(), T - dp[n][j]) - zero.begin() - 1;
            setmax(ans, j + cnt);
        }
    }
    cout << ans << "\n";
    return 0;
}

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

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

    vector<int> vc;
    
    bool state = true;
    // 1を読むとtrue,0を読むとfalse
    int cnt = 0;
    // if(s[0]=='0'){vc.push_back(0);}

    for(int i=0; i<n; i++){
        if(state){
            if(s[i]=='0'){
                vc.push_back(cnt);
                cnt = 1;
                state = false;
            }else{
                cnt++;
            }
        }else{
            if(s[i]=='1'){
                vc.push_back(cnt);
                cnt = 1;
                state = true;
            }else{
                cnt++;
            }
        }
    }
    vc.push_back(cnt);
    if(!state){vc.push_back(0);}    

    int vsize = vc.size();
    vector<int> sumvc;
    sumvc.push_back(vc[0]);
    for(int i=1;i<vsize;i++){
        sumvc.push_back(sumvc[i-1]+vc[i]);
    }

    // debug
    // for (int j=0; j<sumvc.size();j++){
    //     cout << sumvc[j] << endl;
    // }
    // debug

    int max = 0;
    int lsize = (vsize / 2) - k + 1;
    

    // cout 
    // cout << lsize <<endl;
    // cout << "----" << endl;
    if (lsize>0){
        max = sumvc[k*2];  
        for (int i=1;i<lsize;i++){
            int tmp = sumvc[(i+k)*2] - sumvc[i*2-1];
            if(tmp>max){
                max = tmp;
            }
            // cout << max << endl;
        }
    }else{
        max = n;
    }
    
 
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 1528
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = int_fast64_t;
using P = pair<i64,i64>;

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

    int ans = 0;
    int MIN = 0, MAX = N+1;
    while(MAX - MIN > 1){
        int mid = (MAX + MIN) / 2;
        bool ok = false;

        deque<char> a;
        for(int left = 0; left < mid-1; left++) a.push_back(S[left]);
        
        map<deque<char>, int> mp;
        for(int left = mid-1; left < N; left++){
            a.push_back(S[left]);
            if(mp.count(a)){
                if(left - (mid-1) > mp[a]){
                    //cout << left << " " << mid << endl;
                    ok = true;
                    break;
                }
            }
            else mp[a] = left;
            a.pop_front();
        }

        if(ok) {
            ans = max(ans, mid);
            MIN = mid;
        } else {
            MAX = mid;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    string S;
    cin >> S;
    int res = 0;
    rep0(i,4){
        if(S[i]=='+'){
            res++;
        }else{
            res--;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3636
def main():
    n, m = map(int, input().split(' '))
    a_s = list(map(lambda x: [1, int(x)], input().split(' ')))
    data = [list(map(int, input().split(' '))) for _ in range(m)]
    data = sorted(data + a_s, key=lambda x: x[1])

    result = 0

    for _ in range(n):
        if data[-1][0] == 0:
            del data[-1]
        result += data[-1][1]
        data[-1][0] -= 1
    print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 47788
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

const i64 MOD = 2019;

int main()
{
  i64 l, r;
  cin >> l >> r;
  i64 ans = 1e18;
  for (i64 i = l; i <= min(r, l + MOD * 2); i++)
    for (i64 j = i + 1; j <= min(r, l + MOD * 2); j++)
      ans = min(ans, i * j % MOD);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

a,b,c = input().split()
if a[-1] == b[0] and b[-1] == c[0]:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3316
/*
  AOJ 2138
  Title:Vending Machine
  @kankichi573
*/
#include <stdio.h>
#include <string.h>

#define LIMIT 100000
int n,m;
int denomi[10];
int table[LIMIT+1];
int gr;

int min(int x,int y)
{
  if(x<y)
    return(x);
  else
    return(y);

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

}

void dump()
{
  int i;
  for(i=1;i<=m;i++)
    if(table[i]<LIMIT)
      printf("%d:%d,",i,table[i]);
  printf("\n");
}

greed(int kin[],int n,int m)
{
  int highest,min_,i,count;

  highest=kin[0];
  //printf("gr=%d [%d][%d]\n",m,highest,n);
  if(m==0)
    return(0);
  if(m < highest && n>1)
    return(greed(kin+1,n-1,m));
  if(n==1)
    {
      if((m%highest)==0)
	return(m/highest);
      else
	return(LIMIT);
    }
  min_=LIMIT;
  for(i=m/highest;i>=0;i--)
    {
      //printf("i=%d\n",i);
      count=max(i,greed(kin+1,n-1,m-i*highest));
      if(min_>count)
	{
	  min_=count;
	  break;
	}
    }
  return(min_);
}


void solve()
{
  int i,j,k,kin,wk;

  for(i=1;i<=m;i++)
    table[i]=LIMIT;

  kin=denomi[0];
  for(i=0;i*kin<=m;i++)
    table[i*kin]=i;
  //dump();
  for(i=1;i<n;i++)
    {
      kin=denomi[i];
      for(j=m;j>=0;j--)
	if(table[j]!=LIMIT)
	  {
	    for(k=1;j+kin*k<=m && k<=gr;k++)
	      {
		if(table[j+kin*k]>(wk=max(k,table[j])))
		  table[j+kin*k] = wk;
		else
		  break;
	      }
	  }
      //dump();
    }
    
}


int compare(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}


main()
{
  int i,ret;
  while(scanf("%d %d",&n,&m) && (n||m))
    {
      for(i=0;i<n;i++)
	scanf("%d",&denomi[i]);
      qsort(denomi,n,sizeof(int),compare);
      gr=greed(denomi,n,m);
      //printf("greed=%d\n",gr);
      solve();
      printf("%d\n",table[m]);
    }
  return(0);
}

Measured memory_bytes: 992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int n,a,b; cin>>n>>a>>b;
    cout<<min(a*n,b)<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
import itertools
import math

N=int(input())
T,A=[int(x) for x in input().split()]
H=[int(x) for x in input().split()]

d=[(abs((T*1000-h*6)-A*1000),i+1) for i,h in enumerate(H)]

print(min(d)[1])


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

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

    int n;
    cin >> n;
    map<int, int> m;
    m[0] = 1;

    int sum = 0, ans = 0;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        sum += x;
        ans += m[sum];
        m[sum]++;
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 12800
n = int(input())
count = 0
ans = 0

for i in range(1, n+1) :
    if i % 2  == 0:
        continue
    for j in range(1, i+1):
        if i % j == 0:
            count = count + 1
    if count == 8 :
            ans = ans + 1
    count = 0

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
using namespace std;
int beishu(int cifang,int shu)
{
    long long int sum=1;
    for (int i=1;i<=cifang;i++)
        sum*=shu;
    return sum;
}
int weishu(int x)
{
    int num=0;
    while (x)
    {
        num++;
        x/=10;
    }
    return num;
}
int main()
{
    int a,b;
    cin>>a>>b;
    long long int s;
    s=a*beishu(weishu(b),10);
    s+=b;
    int t=sqrt(s);
    if(t*t==s) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
} 

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

typedef long long ll;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18


int main() {
    ll N,K; cin >> N >> K;
    if(K%2 == 1){
        cout << (N/K)*(N/K)*(N/K) << endl;
    }else if(K%2 == 0){
        ll a = N/(K/2) - N/K;
        ll b = N/K;
        cout << a*a*a + b*b*b << endl;
    }
    

    return 0;
}

Measured memory_bytes: 3636
using System;
using System.Linq;

class Program
{
    public static void Main(string[] args)
    {
        string Raw;
        while ((Raw = Console.ReadLine()) != null)
        {
            string Bin = Convert.ToString(int.Parse(Raw), 2);
            string Out = "";
            
            for (int i = Bin.Length - 1; i >= 0; i--)
                if (Bin[i] == '1')
                    Out += Math.Pow(2, Bin.Length - 1 - i).ToString() + " ";
            
            Console.WriteLine(Out.Trim());
        }
    }
}

Measured memory_bytes: 9276
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <set>
#include <bitset>
#include <stack>
//#include <atcoder/dsu>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
//using namespace atcoder;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

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

lli gcd2(lli x, lli y)
{
    lli t;
    while (y != 0)
        t = x % y, x = y, y = t;
    return (x);
}

lli lcm2(lli x, lli y)
{
    lli xy = x * y;
    if (xy < 0)
        xy = -xy;
    return (xy / gcd2(x, y));
}
lli m = 1e9 + 7;
int main(void)
{
    int N;
    cin >> N;
    map<int, int> a;
    for (int i = 0; i < N; i++)
    {
        int tmp;
        cin >> tmp;
        a[tmp] = i + 1;
    }
    for (auto x : a)
    {
        cout << x.second << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int N;
    string S;
    string ans="";
    cin>>N>>S;
    REP(i,S.size()){
        int x =S[i]-'A';
        x=(x+N)%26;
        putchar(x+'A');
    }
    cout <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() { 
  int n;
  cin>>n;
  cout<<n/3<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main()
{
int n;
while(cin>>n)
{
int combo=0;
for(int a=0;a<=9;a++)
{
for(int b=0;b<=9;b++)
{
for(int c=0;c<=9;c++)
{
for(int d=0;d<=9;d++)

if(a+b+c+d==n)
combo++;
}}}
cout<<combo<<endl;
}

return 0;
}

Measured memory_bytes: 1160
import numpy as np
import sys
input = sys.stdin.readline


def main():
    n, s = map(int, input().split())
    A = np.array([int(i) for i in input().split()])

    MOD = 998244353

    dp = np.zeros(s + 1, dtype="int32")
    dp[0] = 1

    for i in range(n):
        p = (dp * 2) % MOD
        p %= MOD
        p[A[i]:] += dp[:-A[i]]
        dp = p % MOD

    print(dp[s])


if __name__ == '__main__':
    main()

Measured memory_bytes: 27404
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  ans=[]
  while True:
    if len(l)==0:
      break
    i=len(l)-1
    f=True
    for _ in range(len(l)):
      if l[i]==i+1:
        ans.append(l[i])
        l=l[:i]+l[i+1:]
        f=False
        break
      i-=1
    if f:
      print(-1)
      exit()
  ans.reverse()
  for x in ans:
    print(x)

main()
# print(main())


Measured memory_bytes: 6220
#include <bits/stdc++.h>
 
#define ll long long
#define X first
#define Y second
#define MP make_pair
#define ld long double
 
using namespace std;
 
const int N = 5e5 + 123;
const ll mod = 1e9 + 7;

ll a[N], dp[N];
int n, k;

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

	cin >> n >> k;
	for(int i = 1;i <= n;i++)
		cin >> a[i];
	for(int i = 2;i <= n;i++){
		dp[i] = N * 1ll * N;
		for(int j = i;j >= max(1, i - k);j--){
			dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
		}
	}
	cout << dp[n];
}

Measured memory_bytes: 5120
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
typedef pair<int, char> P;

pair<int, char> parse(string s) {
    pair<int, char> ret(0, '.');
    string::const_iterator pt = s.begin();
    while (*pt == '.') {
        pt++;
        ret.first++;
    }
    ret.second = *pt;

    return ret;
}

int expression(vector<P> vp, int &pt, int level = 0) {
    if (isdigit(vp[pt].second)) {
        return vp[pt++].second - '0';
    } else if (vp[pt].second == '+') {
        int ret = 0;
        pt++;
        while (pt < vp.size() && level < vp[pt].first) {
            ret += expression(vp, pt, level + 1);
        }
        return ret;
    } else {
        int ret = 1;
        pt++;
        while (pt < vp.size() && level < vp[pt].first) {
            ret *= expression(vp, pt, level + 1);
        }
        return ret;
    }
}

bool solve() {
    int n;
    cin >> n;
    if (n == 0) return false;
    vector<P> lines;

    rep(i, 0, n) {
        string s;
        cin >> s;
        lines.push_back(parse(s));
    }
    int pt = 0;
    int ans = expression(lines, pt);
    cout << ans << endl;
    return true;
}


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

    while (solve()) {

    }

    return 0;
}



Measured memory_bytes: 3208
integer(8) n, c, s
integer(8), allocatable :: a(:)
read *, n
allocate(a(n))
read *, a
c = count(a < 0)
a = merge(-a, a, a < 0)
s = sum(a)
print *, merge(s, s - minval(a) * 2, mod(c, 2) == 0)
end


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

template <int mod>
struct ModInt {
    int val;
    ModInt() : val(0) {}
    ModInt(long long x) : val(x >= 0 ? x % mod : (mod - (-x) % mod) % mod) {}
    int getmod() { return mod; }
    ModInt &operator+=(const ModInt &p) {
        if ((val += p.val) >= mod) {
            val -= mod;
        }
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if ((val += mod - p.val) >= mod) {
            val -= mod;
        }
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        val = (int)(1LL * val * p.val % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }
    ModInt operator-() const { return ModInt(-val); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return val == p.val; }
    bool operator!=(const ModInt &p) const { return val != p.val; }
    ModInt inverse() const {
        int a = val, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    ModInt pow(long long n) const {
        ModInt ret(1), mul(val);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.val; }
    friend istream &operator>>(istream &is, ModInt &a) {
        long long t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }
    static int get_mod() { return mod; }
};
const int MOD = 1000000007;  // if inv is needed, this shold be prime.
using modint = ModInt<MOD>;

int main() {
    int N;
    cin >> N;
    vector<int> A(N - 1), ans(N, 0);
    for (int i = 0; i < N - 1; i++) {
        cin >> A.at(i);
        ans[A[i] - 1]++;
    }
    for (auto a : ans) {
        cout << a << "\n";
    }
}


Measured memory_bytes: 4804
#include<bits/stdc++.h>
#define INF 1e7

using namespace std;
typedef long long int ll;

int main()
{
    int H,W; cin >> H >> W;
    vector<vector<int>>cost(10,vector<int>(10)); for(int i = 0; i < 10; i++) for(int j = 0; j < 10; j++) cin >> cost[i][j];
    vector<vector<int>>A(H,vector<int>(W)); for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) cin >> A[i][j];
    for(int k = 0; k < 10; k++)
    {
        for(int i = 0; i < 10; i++)
        {
            for(int j = 0; j < 10; j++)
            {
                cost[i][j] = min(cost[i][j],cost[i][k] + cost[k][j]);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            if(A[i][j] == -1 || A[i][j] == 1) continue;
            ans += cost[A[i][j]][1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3768
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

 class Main {
	public static void main(String[]args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
	    int arr[] = new int[n];
	    int arr2[] = new int[m];
	    for(int i = 0 ; i < n ; i++) {
	    	arr[i] = scan.nextInt();
	    }
	    for(int i = 0 ; i < m ; i++) {
	    	arr2[i] = scan.nextInt();
	    }
	    Arrays.sort(arr);
	    Arrays.sort(arr2);
	    if(arr[arr.length-1] < arr2[0] && x < arr2[0] && x < y && y>=arr2[0]) {
	    	System.out.println("No War");
	    }else {
	    	System.out.println("War");
	    }
	    
	}
}	

Measured memory_bytes: 23764
#include <bits/stdc++.h>
# define REP(i,n,N) for(int i=n;i<N;i++)
# define p(S) cout<<S<<endl;
#define ll long long
using namespace std;


ll l, k;
ll dp[110];
int main() {
    cin>>l>>k;
    dp[0]=0;
    dp[1]=1;
    if(k<=l) dp[k]=1;

    REP(i, 0, l){
        if(i+2 <= l){
            dp[i+2]+=dp[i];
        }
        if(i+k+1<=l){
            dp[i+1+k]+=dp[i];
        }
    }

    ll ans=0;
    REP(i, 0, l+1){
        ans+=dp[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3116
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import perm
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

########

N, D = l_inpl()

ans = 0
cnt = 0
while True:
    ans += 1 + 2*D
    cnt += 1
    if ans >= N:
        break
print(cnt)

# print(3*(r**2))

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() {
    init();

    string s;
    cin >> s;

    string a = "KIHBR5", ans = "YES\n";
    int b[6] = { 1,0,0,1,1,1 };
    int itr = 0, cnt = 0;
    for (char i : s) {
        if (i == 'A')cnt++;
        else if (i == a[itr])cnt = 0, itr++;
        else ans = "NO\n";
        if (cnt > b[itr])ans = "NO\n";
    }
    if (itr != 5)ans = "NO\n";
    cout << ans;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(aa,bb,cc) for(int aa=(bb);aa<=(int)(cc);++aa)
#define Pair pair<int,int>
#define mk(x,y) make_pair(x,y)
#define x first
#define y second
using namespace std;
const int maxn=5e5+10;
const int inf=0x3f3f3f3f;
int n;
char s[maxn];
vector<Pair>G[maxn];
vector<int>pos;
int dp[maxn];

template<class T>void read(T &x){
	x=0;char c=getchar();bool symbol=0;
	while(!isdigit(c)) symbol|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	x=symbol?-x:x;
}

int main(){
	read(n);
	scanf("%s",s+1);
	pos.push_back(0);
	For(i,1,n) if(s[i]=='0') pos.push_back(i);
	pos.push_back(n+1);
	//For(i,0,pos.size()-1) printf("%d ",pos[i]);puts("");
	For(i,1,pos.size()-1){
		int l=pos[i-1],r=pos[i];
		if(s[l-1]=='1') For(j,l+1,r-1) G[j].push_back(mk(l-1,j-l));
		if(s[r+1]=='1') For(j,l+1,r-1) G[r+1].push_back(mk(j,r-j));
	}
	//For(i,1,n) sort(G[i].begin(),G[i].end()),G[i].erase(unique(G[i].begin(),G[i].end()),G[i].end());
	//For(i,1,n) For(j,0,G[i].size()-1) printf("%d %d %d\n",G[i][j].x,i,G[i][j].y);
	For(i,1,n){
		For(j,0,G[i].size()-1)
			dp[i]=max(dp[i],dp[G[i][j].x-1]+G[i][j].y);
		dp[i]=max(dp[i],dp[i-1]);
	}
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 35328
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s; cin >> s;
  int n[4];
  rep(i, 4) n[i] = s[i]-'0';
  rep(i, 1<<3) {
    int sum = n[0];
    string ans;
    ans += s[0];
    rep(j, 3) {
      if((i>>j)&1) {
        sum += n[j+1];
        ans += '+';
      } else {
        sum -= n[j+1];
        ans += '-';
      }
      ans += s[j+1];
    }
    if(sum == 7) {
      cout << ans << "=7" << endk;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i = m; i < n; i++)
#define printhello std::cout << "hello" << endl;
using ll=long long;
using namespace std;

int main(){
    string s,t;
    cin >> s >> t;
    int count = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] != t[i]) count++;
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 3820