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

using namespace std;
const int N = 110;
int _w;

int n, a[N];
vector<int> ans;

int main() {
	cin >> n;
	for( int i = 1; i <= n; ++i )
		cin >> a[i];
	while(n) {
		bool flag = false;
		for( int i = n; i >= 1; --i )
			if( a[i] == i ) {
				ans.push_back(i);
				for( int j = i; j < n; ++j )
					a[j] = a[j+1];
				--n;
				flag = true;
				break;
			}
		if( flag == false ) {
			puts("-1");
			return 0;
		}
	}
	for( auto it = ans.rbegin(); it != ans.rend(); ++it )
		printf( "%d\n", *it );
	return 0;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(int n){
    cout << "Yes" << endl;
}

void no (int n){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

int main() {
    vector<int> ar(5);
    rep(i,5) cin >> ar[i];
    int ans = 0;
    rep(i,5) ans += cel(ar[i],10);
    int mi = 10;
    rep(i,5) if (ar[i] % 10 != 0) mi = min(mi,ar[i] % 10);
    cout << ans*10 - 10 + mi << endl;
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    deque<char> dq;
    string s;
    cin >> s;
    for (int i = 0; i < (int) s.size(); ++i) {
        dq.push_back(s[i]);
    }
    int n;
    bool forward = true;
    cin >> n;
    while (n--) {
        int type;
        cin >> type;
        if (type == 1) {
            forward = !forward;
        } else {
            int f;
            char ch;
            cin >> f >> ch;
            if ((f == 1 && forward) || (f == 2 && !forward)) {
                dq.push_front(ch);
            } else {
                dq.push_back(ch);
            }
        }
    }
    if (!forward) reverse(dq.begin(), dq.end());
    for (int i = 0; i < (int) dq.size(); ++i) {
        cout << dq[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 976
#include<iostream>
#include<cstdio>
#include<string>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<list>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<string.h>
#include<limits.h>
#include<functional>
using namespace std;

signed main() {
	int a, b, c; cin >> a >> b >> c;
	if (c - b == b - a)puts("YES");
	else puts("NO");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define maxn 5001
#define inf 1000000000000000000
ll p[maxn], pos[maxn], dp[maxn][maxn];
using namespace std;
int main()
{
    ll n, a, b, ans=inf;
    cin>>n>>a>>b;
    for(int i=1; i<=n; i++) cin>>p[i], pos[p[i]]=i;
    memset(dp, 1000000, sizeof dp);
    dp[0][0]=0;
    for(int i=1; i<=n; i++){
        for(int j=0; j<i; j++){
            if(pos[i]>pos[j]){
                dp[i][i]=min(dp[i-1][j], dp[i][i]);
                dp[i][j]=dp[i-1][j]+b;
            }
            else dp[i][j]=dp[i-1][j]+a;
        }
    }
    for(int i=1; i<=n; i++) ans=min(ans, dp[n][i]);
    cout<<ans;
}


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

using namespace std;
vector<vector<int>> a;

void dfs(int p, vector<int>& d, int c = 0){
	if(d[p] <= c) return;
	d[p] = c;
	for(int i = 0; i < a[p].size(); i++){
		dfs(a[p][i], d, c + 1);
	}
	return;
}

int main(){
	int n, ans = 0;
	cin >> n;
	a = vector<vector<int>>(n + 1);
	for(int i = 0; i < n - 1; i++){
		int x, y;
		cin >> x >> y;
		a[x].push_back(y);
		a[y].push_back(x);
	}
	vector<int> d1(n + 1, n + 100), d2(n + 1, n + 100);
	dfs(1, d1);
	dfs(n, d2);
	int b = 0, w = 0;
	for(int i = 1; i <= n; i++){
		if(d1[i] <= d2[i]){
			b++;
		}else{
			w++;
		}
	}
	cout << (( b > w )? "Fennec" : "Snuke") << endl;
	return 0;
}

Measured memory_bytes: 11136
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
using namespace std;

const int N=1000005;
const int M=N<<1;

struct E{
	int to,next;
}mem[M];
int n,m,x,y,k,u,num,I,P,Q,sz;
bool tag;
int head[N],dis[N];
bool vis[N];
queue<int> q;

void add(int x,int y){
	num++;
	mem[num].to=y; mem[num].next=head[x];
	head[x]=num;
}

int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		add(x,y); add(y,x);
	}
	for (int i=1;i<=n;i++){
		if (vis[i]) continue;
		while (!q.empty()) q.pop();
		sz=1; tag=1;
		q.push(i); vis[i]=1; dis[i]=0;
		while (!q.empty()){
			k=q.front(); q.pop();
			for (int j=head[k];j;j=mem[j].next){
				u=mem[j].to;
				if (!vis[u]){
					vis[u]=1;
					sz++;
					q.push(u);
					dis[u]=dis[k]+1;
				}
				else{
					if ((dis[k]-dis[u])%2==0) tag=0;
				}
			}
		}
		if (sz==1) I++;
		else{
			if (tag) Q++;
			else P++;
		}
	}
	printf("%lld\n",2ll*I*n-1ll*I*I+1ll*P*P+2ll*P*Q+2ll*Q*Q);
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i = 0; i < N; i++){
    cin >> d.at(i);
  }
  
  int current = 10000;
  int height = 0;
  vector<int>::iterator maxIter;
  size_t maxIndex;
  for(int i = 0; i < N; i++){
  	maxIter = max_element(d.begin(), d.end());
  	maxIndex = distance(d.begin(), maxIter);
    if(d.at(maxIndex) < current){
      height++;
    }
    current = d.at(maxIndex);
    d.at(maxIndex) = 0;
  }
  cout << height << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int j,s_length = 0;
	char s[101],p[101];
	scanf("%s",s);
	scanf("%s",p);

	for(int i = 0; s[i] != '\0';i++) s_length++;

	for(int left = 0;s[left] != '\0';left++){
		for(j = 0;p[j] != '\0' && p[j] == s[(left+j)%s_length];j++);
		if(p[j] == '\0'){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

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

long long x;

int main () {
	long long ans = 0;
	scanf("%ld", &x);
	
	long long a = x / 11;
	long long b = x % 11;
	ans = a*2;
	if (b > 6) {
		ans += 2;
	} else if (b != 0) {
		ans += 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int isprime(int num){
  int i;

  if(num == 2) return 1;

  if(num < 2 || num % 2 == 0) return 0;


    i = 3;
    while(i <= sqrt((double)num) ){
      if(num % i == 0) return 0;
      i = i + 2;
    }

    return 1;
}

int main(){
  int i,N,A[10000],c=0;

  scanf("%d", &N);
  for(i = 0 ; i < N ; i++){
    scanf("%d", &A[i]);
    c += isprime(A[i]);
  }

  printf("%d\n", c);
  return 0;
}


Measured memory_bytes: 2144
a1,a2,a3 = map(int, input().split())
a_list = [a1,a2,a3]
a_list_sort = sorted(a_list)
ans_1 = a_list_sort[1]-a_list_sort[0]
ans_2 = a_list_sort[2]-a_list_sort[1]
print(ans_1+ans_2)

Measured memory_bytes: 2940
s=list(map(str,input()))
l=[[]]
count=0
for i in s:
    if i=='A' or i=='C' or i=='G' or i=='T':
        l[count].append(i)
    else:
        count+=1
        l.append([])
maxl=0
for j in l:
    if len(j)>maxl:
        maxl=len(j)
print(maxl)

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

int main(){
  
  int N,K,x,sum = 0;
  cin >> N >> K;
  
  for(int i = 0;i < N;i++){
    cin >> x;
    
    if(x * 2 < (K - x)  * 2){
      sum += x * 2;
    }else{
      sum += (K - x) * 2;
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 300005
#define L (cur*2)
#define R (L+1)
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
int n,q;
int mnr[M*4], sum[M*4], posl[M*4];
char buf[M];

void up(int cur,int ll,int rr)
{
	sum[cur] = sum[L] + sum[R];
	posl[cur] = min(posl[L], posl[R]);
	mnr[cur] = min(mnr[R], sum[R]+mnr[L]);
}
void init(int cur,int ll,int rr)
{
	if(ll==rr)
	{
		if(buf[ll]=='(')
		{
			sum[cur] = mnr[cur] = -1;
			posl[cur] = M;
		}
		else
		{
			sum[cur] = mnr[cur] = 1;
			posl[cur] = ll;
		}
		return;
	}

	int mid = (ll+rr)/2;
	init(L,ll,mid);
	init(R,mid+1,rr);
	up(cur,ll,rr);
}
void upd(int cur,int ll,int rr,int x,int v)
{
	if(ll==rr)
	{
		sum[cur] = mnr[cur] = v;
		
		if(v==-1) posl[cur]=M;
		else posl[cur]=ll;
		return;
	}

	int mid = (ll+rr)/2;
	if(x<=mid) upd(L,ll,mid,x,v);
	else upd(R,mid+1,rr,x,v);
	up(cur,ll,rr);
}
int ask(int cur,int ll,int rr,int s)
{
	if(ll==rr)
	{
		if(s!=mnr[cur]) return -1;
		return ll;
	}

	int mid = (ll+rr)/2;
	
	if(mnr[R] > s)
	{
		int re = ask(L,ll,mid,s-sum[R]);
		if(re!=-1) return re;
		return mid+1;
	}
	return ask(R,mid+1,rr,s);
}

int main()
{
	int x;
	RI(n,q);
	scanf("%s", buf+1);
	init(1,1,n);

	while(q--)
	{
		scanf("%d",&x);
		if(buf[x]=='(')
		{
			buf[x] = ')';
			upd(1,1,n,x,1);
			
			x = posl[1];
			buf[x] = '(';
			upd(1,1,n,x,-1);
			printf("%d\n",x);
		}
		else
		{
			buf[x] = '(';
			upd(1,1,n,x,-1);

			x = ask(1,1,n,-1);
			buf[x] = ')';
			upd(1,1,n,x,1);
			printf("%d\n", x);
		}
	}
	return 0;
}

Measured memory_bytes: 15512
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 1e9 + 7;
const long long inf = 1e18;
 
using namespace std;
 

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 
ll binomialCoeff(ll n, ll k) 
{ 
	ll C[n + 1][k + 1]; 
	ll i, j; 


	for (i = 0; i <= n; i++) 
	{ 
		for (j = 0; j <= min(i, k); j++) 
		{ 
			
			if (j == 0 || j == i) 
				C[i][j] = 1; 

			else
				C[i][j] = (C[i - 1][j - 1] + 
										C[i - 1][j])%MOD; 
		} 
	} 

	return C[n][k]; 
}
bool compare(const string &a , const string&b){
	
}
 
void solve()
{
   int n ; 
   cin>>n ; 
   ll a[n] ;
   rep(i , n)cin>>a[i] ;
   sort(a , a+n) ;
   
   int cou  = n-2 ;
   int i = n-2 ;
   ll ans = a[n-1] ;
   while(cou){
   	if(cou==1){
   		ans += a[i] ;
   		cou--;
   	}
   	else{
   		ans += 2*a[i] ;
   		cou -= 2 ;
   		i--;
   	}
   }
   cout<<ans<<endl;
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 5424
object Main extends App {
  import scala.io.StdIn._
  val MOD = 1000000007L
  val str = readLine.trim
  var digit = 1
  val count = Array.fill(13){0L}
  count(0) = 1
  for (c <- str.reverse) {
    val temp = Array.fill(13){0L}
    c match {
      case '?' =>
        for (d <- 0 until 10) {
          val diff = d * digit
          for (p <- 0 until 13) {
            temp((p + diff) % 13) += count(p)
          }
        }
      case _ =>
        val diff = c.asDigit * digit
        for (p <- 0 until 13) {
          temp((p + diff) % 13) += count(p)
        }
    }
    for (i <- 0 until 13) {
      count(i) = temp(i) % MOD
    }
    digit = (digit * 10) % 13
  }
  println(count(5))
}

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

typedef long long ll;
typedef pair <int , int> pii;

const int N = 3e2+10 , mod = 998244353;

int dp[N][N][N] , ps[N][N][N] , ps2[N][N][N];

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   string s;
   int k;
   cin >> s >> k;
   int n = s.length();
   k = min(k , n);
   int cur = 0;
   vector <int> v;
   for(int i = 0 ; i < n ; i++)
      if(s[i] == '0'){
         v.push_back(cur);
         cur = 0;
      }
      else{
         cur++;
      }
   v.push_back(cur);
   n = v.size();
   dp[n][0][0] = 1;
   ps[n][0][0] = 1;
   for(int i = 0 ; i <= k ; i++)
      ps2[n][i][i] = 1;
   int ans = 0;
   for(int i = n - 1 ; i >= 0 ; i--){
      for(int j = 0 ; j <= k ; j++){
         for(int p = 0 ; p <= k ; p++){
            dp[i][j][p] += ((ps2[i + 1][j][p] - ((j > v[i]) ? ps2[i + 1][j - v[i] - 1][p - v[i] - 1] : 0) + ps[i + 1][j][p] - dp[i + 1][j][p]) % mod + mod) % mod;
            dp[i][j][p] %= mod;
            ps2[i][j][p] = dp[i][j][p];
            if(j && p){
               ps2[i][j][p] += ps2[i][j - 1][p - 1];
               ps2[i][j][p] %= mod;
            }
            //cout << i << " " << j << " " << p << " " << dp[i][j][p] << endl;
         }
         for(int p = k ; p >= 0 ; p--)
            ps[i][j][p] = (dp[i][j][p] + ps[i][j][p + 1]) % mod;
      }
   }
   for(int j = 0 ; j <= k ; j++){
      ans += ps[1][j][0];
      ans %= mod;
   }
   cout << ans;
   return 0;
}


Measured memory_bytes: 170384
#include<bits/stdc++.h>
using namespace std;
#define Mx 2000001

typedef long long  L;
typedef pair<L, L> pii;
L a,a1,a2,a3,b,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,k,l,m,n,m1,m2,n1,n2,o,p,p1,p2,p3,p4,q,q1,q2,q3,q4,r,s,t,
u,v,x,y,z,sum,mx,mn,flg,flg1,flg2,id1,id2,id3,id4,lim,id;
L A[Mx],B[Mx];
void solve(){
   id=n-1;
    for(L i=1;i<n;i++){
        A[i]=id--;
    }
    for(L i=1;i<n;i++){
        d1=abs(i-x);
        flg=0;
        for(L j=n;j>i;j--){
            d2=(abs(j-y));
            d4=d1+d2+1;
            d3=abs(i-j);
            if(d3>d4){
                flg=1;
                A[d3]--;A[d4]++;
            }else break;
        }
        if(flg==0)break;
    }
    for(L i=1;i<n;i++){
        printf("%lld\n",A[i]);
    }
}
int main()
{
    scanf("%lld%lld%lld",&n,&x,&y);
    solve();
    return 0;
}
/// lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


Measured memory_bytes: 2304
fn main() {
    let (a, b, c, k) = input();
    println!("{}", solve(a, b, c, k));
}

fn input() -> (i32, i32, i32, i32) {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();
    let c: i32 = iter.next().unwrap().parse().unwrap();
    let k: i32 = iter.next().unwrap().parse().unwrap();
    (a, b, c, k)
}

fn solve(a: i32, b: i32, c: i32, k: i32) -> i32 {
    let mut res = 0;
    if a - k >= 0 {
        return k;
    } else {
        res = a;
    }
    let mut remain = k - a;
    if b - remain >= 0 {
        return res;
    }
    remain  = remain - b;
    res - remain
}

Measured memory_bytes: 2108
#include<stdio.h>
int n,h[100000],i,r=0,q=0;
int main(){
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d",&h[i]);
    for(i=0;i<n-1;i++){
        q=h[i]>=h[i+1]?q+1:0;
        if(r<q)r=q;
    }
    printf("%d",r);
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <iomanip>

#include <map>
#include <set>
#include <queue>
#include <stack>

#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdbl vector<double>
#define vstr vector<string>

using namespace std;

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

vint es[2001];

int dfs(int u, int p, int h, int mh){
	int cnt = 0;
	if(h > mh) cnt++;

	for(int v : es[u]){
		if(v != p) cnt += dfs(v, u, h+1, mh);
	}
	return cnt;
}

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

	int N,K;
	cin >> N >> K;

	rep(i,N-1){
		int a,b;
		cin >> a >> b;
		a--;
		b--;

		es[a].push_back(b);
		es[b].push_back(a);
	}

	int ans = 1e7;

	if(K % 2 == 0){
		// Kが偶数なら頂点の走査
		rep(i,N){
			int mn = 0;
			for(int j : es[i]) {
				mn += dfs(j,i,1,K/2);
			}
			ans = min(ans,mn);
		}
	}else{
		// Kが奇数なら辺の走査
		rep(i,N){
			for(int j : es[i]){
				int mn = dfs(i,j,1,(K-1)/2+1) + dfs(j,i,1,(K-1)/2+1);
				ans = min(ans,mn);
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int MAXN = 100005;

int k, ans = 50, f[MAXN][50];
// f[i][j] i Ä£kÈ¡ÓàÊý j ÊýÎ»ºÍ

void dfs( int x , int y ){
	if( f[x][y] ) return;
	else f[x][y] = 1;
	if( !x ) ans = min( ans, y );
	for( int i = 0; i <= 9; ++i ) if( y + i <= 46 )
		dfs( ( x * 10 + i ) % k, y + i );
}

int main(){
	scanf( "%d", &k );
	for( int i = 1; i <= 9; ++i )
		dfs( i % k, i );
	printf( "%d\n", ans );
	return 0;
}

Measured memory_bytes: 122112
#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);
#define fi(a,b,c) for(int i=a;i<b;i=i+c)
#define fj(a,b,c) for(int j=a;j<b;j+=c)
using namespace std;
 
ll gcd(ll n1,ll n2) {
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent) {
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
ll max(ll a,ll b,ll c) {
	return max(a,max(b,c));
}
int max(int a,int b,int c) {
	return max(a,max(b,c));
}

int ver(int a, int b, int c){
	if(a+b>c && a+c>b && b+c>a){
		return 1;
	}
	return 0;
}

int main()
{
	int n;
	ll sum=0;
	sd(n);
	vi l;
	std::map<int, int> map;
	fi(0,n,1){
		int li;
		sd(li);
		if(map[li]){
			map[li]++;
		}else{
			l.pb(li);
			map[li]=1;
		}
	}
	sort(l.begin(), l.end());

	for(int i=0;i<l.size();i++){
		for(int j=i+1;j<l.size();j++){
			for(int k=j+1;k<l.size();k++){
				sum+=ver(l[i], l[j], l[k])*map[l[i]]*map[l[j]]*map[l[k]];
			}
		}
	}
	plld(sum);
}

Measured memory_bytes: 3800
import sys

while True:
	n, x = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
	if 0 == n and 0 == x:
		break
		
	cnt = 0
	for i in range( 1, n-1 ):
		if  x <= i:
			break
		for j in range( i+1, n ):
			if  x <= ( i+j ):
				break
			for k in range( j+1, n+1 ):
				s = ( i + j + k )
				if x == s:
					cnt += 1
					break
				elif   x < s:
					break
	
	print( cnt )

Measured memory_bytes: 6724
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#define re register
using namespace std;
typedef long long ll;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=2000+10;

int n,x;
int a[N],w[N];

int main() {
    n=read(),x=read();
    for (re int i=0;i<n;++i) a[i]=read();
    memset(w,0x3f,sizeof(w)); ll ans=1e18;
    for (re int i=0;i<n;++i) {
        for (re int j=0;j<n;++j) w[j]=min(w[j],a[(j-i+n)%n]);
        ll now=0;
        for (re int j=0;j<n;++j) now+=w[j];
        ans=min(now+1ll*i*x,ans);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
char ch;
int s=0,e=0;
int len=0;

while (1)
{
  scanf("%c",&ch);
  if (ch=='\n'){break;}
  
  len++;
  if (s==0){
    if (ch=='A'){s=len;}
  }else{
    if (ch=='Z'){e=len;}
  }
}
printf("%d",e-s+1);
return 0;

}

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

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

  map<string, int> s;

  for (int i = 0; i < n; i++) {
    string t;
    cin >> t;
    s[t]++;
  }

  cout << s.size() << endl;
}

Measured memory_bytes: 19124
using System;


namespace AtC
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] antennas = new int[5];
            for (int i = 0; i < 5; i++)
                antennas[i] = int.Parse(Console.ReadLine());
            int k = int.Parse(Console.ReadLine());
            for (int i = 0; i < 5; i++)
            for (int r = i + 1; r < 5; r++)
                if (antennas[r] - antennas[i] > k)
                {
                    Console.WriteLine(":(");
                    return;
                }

            Console.WriteLine("Yay!");
        }
    }
}

Measured memory_bytes: 13012
#include <bits/stdc++.h>
using namespace std;
#define modulo p
#define mod(mod_x) ((((long long)mod_x))%modulo)
#define Inf 10000000000000000

int p;

//aのb乗
int beki(int a,int b){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=mod(x*a);
		}
		a=mod(a*a);
		b>>=1;
	}
	return x;
}

//aの逆元
int gyakugen(int a){
	return beki(a,modulo-2);
}

struct combi{
	deque<int> kaijou;
	deque<int> kaijou_;
	
	void kaijou_set(int n){
		kaijou.push_back(1);
		for(int i=1;i<=n;i++){
			kaijou.push_back(mod(kaijou[i-1]*i));
		}
		
		int b=gyakugen(kaijou[n]);
		
		/*
		int a = kaijou[n];int b = 1;int m = modulo-2;
		while(m!=0){
			if(m%2){
				b=mod(b*a);
			}
			a=mod(a*a);
			m/=2;
		}
		*/
		kaijou_.push_front(b);
		for(int i=1;i<=n;i++){
			int k=n+1-i;
			kaijou_.push_front(mod(kaijou_[0]*k));
		}
	}
	
	int combination(int n,int r){
		if(r>n)return 0;
		int a = mod(kaijou[n]*kaijou_[r]);
		a=mod(a*kaijou_[n-r]);
		return a;
	}
	
	int junretsu(int a,int b){
		int x = mod(kaijou_[a]*kaijou_[b]);
		x=mod(x*kaijou[a+b]);
		return x;
	}
	
};

int main(){
	
	
	cin>>p;
	
	vector<int> a(p);
	
	for(int i=0;i<p;i++){
		cin>>a[i];
	}
	combi c;
	c.kaijou_set(p-1);
	vector<int> b(p,0);
	
	for(int i=0;i<p;i++){
		if(a[i]==0)continue;
		int y = beki(i,p-1);
		int gyaku = gyakugen(i);
		for(int j=0;j<p;j++){
			int x = c.combination(p-1,j);
			if(j==p-1)y=1;
			int z = mod(x*y);
			if((p-1-j)%2==1)z*=-1;
			b[j] = mod(b[j]-z);
			if(b[j]<0)b[j]+=modulo;
			y = mod(y*gyaku);
		}
		b[0]=mod(b[0]+1);
	}
	
	for(int i=0;i<p;i++){
		if(i!=0)cout<<' ';
		cout<<mod(b[i]);
	}
	cout<<endl;
		
	
		
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = 0;
        while (true) {
            a++;
            int b = scanner.nextInt();
            if (b == 0) {
                break;
            }
            System.out.println("Case " + a + ": " + b);

        }
    }
}

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

int main()
{
  string s,t;
  cin>>s>>t;
  int ans=INT_MAX;
  for(int i=0;i<(int)s.length()-(int)t.length()+1;i++)
  {
    int cnt=0;
    for(int j=0,k=i;j<(int)t.length();k++,j++)
    {
      if(s[k]!=t[j])
        cnt++;
    }
    ans=min(ans,cnt);
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,k;
    string s;
    cin >> n >> s >> k;
    for (int i=0;i<n;i++) {
        if (s.at(i)!=s.at(k-1)) s.at(i)='*';
    }
    cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string a, b;
    cin >> a >> b;
    int n   = a.size();
    a       = a + a + a;
    b       = b + b + b;
    int ret = 100000000;
    auto f  = [&]() {
        vector<int> bl(3 * n, -1), br(3 * n, 3 * n);
        for (int i = 0; i < 3 * n; ++i) {
            if (i)
                bl[i] = bl[i - 1];
            if (b[i] == '1')
                bl[i] = i;
        }
        for (int i = 3 * n - 1; i >= 0; --i) {
            if (i != 3 * n - 1)
                br[i] = br[i + 1];
            if (b[i] == '1')
                br[i] = i;
        }
        if (bl[n] == -1 && a != b) {
            cout << -1 << "\n";
            exit(0);
        }
        for (int i = 0; i < n; ++i) { // shift
            vector<pair<int, int>> lr = {{0, 0}};
            int temp                  = 0;
            for (int j = n; j < 2 * n; ++j) {
                if (a[j] == b[j + i])
                    continue;
                temp++;
                int l = bl[j + i];
                int r = br[j];
                if (l >= j || r <= j + i)
                    continue;
                lr.emplace_back(j - l, r - (j + i));
            }
            sort(lr.begin(), lr.end());
            multiset<int> r = {0};
            for (auto &p : lr) {
                r.insert(p.second);
            }
            int temp2 = 100000000;
            for (auto &p : lr) {
                r.erase(r.find(p.second));
                int rmax = *r.rbegin();
                int l    = p.first;
                temp2    = min(temp2, 2*(rmax + l));
            }
            ret = min(ret, temp + i + temp2);
        }
    };
    f();
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    f();
    cout << ret << "\n";
    return 0;
}

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

int N, M;
int k[10], s[10][10], p[10];
int ans = 0;

void dfs(int i, bool boolean[10]){
    if (i == N) {
        int ok = 0;
        for (int j = 0; j < M; j++) {
            int on = 0;
            for (int l = 0; l < k[j]; l++) {
                if (boolean[s[j][l] - 1]) on++;
            }
            if (on % 2 == p[j]) ok++;
            else break;
        }
        if (ok == M) ans++;
    }
    else if (i < N) {
        boolean[i] = false;
        dfs(i + 1, boolean);
        boolean[i] = true;
        dfs(i + 1, boolean);
    }
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> k[i];
        for (int j = 0; j < k[i]; j++) {
            cin >> s[i][j];
        }
    }
    for (int i = 0; i < M; i++) cin >> p[i];

    bool boolean[10];
    for (int i = 0; i < N; i++) boolean[i] = false;
    dfs(0, boolean);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int x, y;
	
	scanf("%d %d", &x, &y);
	if(x < y) printf("a < b\n");
	if(x > y) printf("a > b\n");
	if(x == y) printf("a == b\n");

	return 0;
}

Measured memory_bytes: 580
import java.util.Scanner;

public class Main {

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

		StringBuffer line = new StringBuffer(sc.nextLine());
		for (; !line.toString().equals("0");) {
			int sum = 0;
			for (int i = 0; i < line.length(); i++) {
				char ch = line.charAt(i);
				sum += ch - '0';
			}
			System.out.println(sum);
			
			line = new StringBuffer(sc.nextLine());
		}
		
		sc.close();
	}
}

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

int main() {
  int N, TOTAL;
  cin >> N >> TOTAL;
  TOTAL /= 1000;
  const int c10 = min(N, TOTAL / 10);


  for(int i10 = 0; i10 <= c10; i10++) {
    const int c5 = min(N - i10, (TOTAL - 10 * i10) / 5);
    for(int i5 = 0; i5 <= c5; i5++) {
      const int c1 = min(N - i10 - i5, (TOTAL - 10 * i10 - 5 * i5));
      if ((TOTAL - 10 * i10 - 5 * i5 - c1) == 0 && i10 + i5 + c1 == N) {
        cout << i10 << " " << i5 << " " << c1;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int n,w;
    cin>>n>>w;
    int *value=new int[n];
    int *weight=new int[n];
    for(int i=0;i<n;i++){
        cin>>weight[i]>>value[i];
    }
    int **dp=new int*[n];
    for(int i=0;i<n;i++){
        dp[i]=new int[w+1];
    }

    for(int i=0;i<n;i++){
        dp[i][0]=0;
    }

    for(int i=0;i<=w;i++){
        if(i>=weight[0]){
            dp[0][i]=value[0];
        }
        else{
            dp[0][i]=0;
        }
    }

    for(int i=1;i<n;i++){
        for(int j=1;j<=w;j++){
            if(j>=weight[i]){
                dp[i][j]=max(dp[i-1][j],value[i]+dp[i-1][j-weight[i]]);
            }
            else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }

   

    cout<<dp[n-1][w]<<endl;
}

Measured memory_bytes: 78592
import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons, std.typetuple;
import core.bitop, std.datetime;

immutable long mod = 10^^9 + 7;
alias Pair = Tuple!(int, "l", int, "x");

void main(){
    int N, M;
    int li, ri, xi;
    readVars(N, M);

    auto cond = new Pair[][](N + 1);

    foreach(i ; 0 .. M){
        readVars(li, ri, xi);
        cond[ri] ~= Pair(li, xi);
    }

    //writeln(cond);

    auto dp = new int[][][](N + 1, N + 1, N + 1);
    dp[0][0][0] = 1;

    int k, v;

    foreach(r ; 0 .. N + 1){
        foreach(g ; 0 .. N + 1){
            foreach(b ; 0 .. N + 1){
                k = max(r, g, b);
                bool flag;

                foreach(c ; cond[k]){
                    v = (c.l <= r) + (c.l <= g) + (c.l <= b);

                    if (v != c.x) {
                        flag = true;
                        break;
                    }
                }

                if (flag){
                    dp[r][g][b] = 0;
                    continue;
                }

                if (k + 1 <= N) {
                    dp[k + 1][g][b] = (dp[k + 1][g][b] + dp[r][g][b]) % mod;
                    dp[r][k + 1][b] = (dp[r][k + 1][b] + dp[r][g][b]) % mod;
                    dp[r][g][k + 1] = (dp[r][g][k + 1] + dp[r][g][b]) % mod;
                }
            }
        }
    }

    int ans;

    foreach(r ; 0 .. N + 1){
        foreach(g ; 0 .. N + 1){
            ans = (ans + dp[r][g][N]) % mod;
        }
    }

    foreach(r ; 0 .. N + 1){
        foreach(b ; 0 .. N + 1){
            ans = (ans + dp[r][N][b]) % mod;
        }
    }

    foreach(g ; 0 .. N + 1){
        foreach(b ; 0 .. N + 1){
            ans = (ans + dp[N][g][b]) % mod;
        }
    }

    writeln(ans);

}

void readVars(T...)(auto ref T args){
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        throw new Exception("args num < input num");
    }
}

Measured memory_bytes: 193404
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

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

  int left_west = 0, right_east = 0;
  int min_num;

  // leader: str[0]                                                 
  for(int i = 1; i < N; i++){
    right_east += (str[i]=='E');
  }
  min_num = right_east;

  // leader:str[i] 1 <= i <= end                                    
  for(int i = 1; i < N; i++){
    left_west += (str[i-1]=='W');
    right_east -= (str[i]=='E');

    int num = left_west + right_east;
    min_num = min(min_num, num);
  }

  cout << min_num << endl;

  return 0;
}


Measured memory_bytes: 900
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0,d=0,e=0, ans = 0, x = 0, y = 0, z = 0, n = 0, m = 0, maxy = 0, mini = 9999, counter = 0, endp = 0, checker = 0;

std::vector <long long int> vec{}, vecsec{}, vecth{};
long long int iremono[100001], sec[100001];
long long int iremono2[100001], check[100001],xpo[10000001],ypo[10000001],hei[1000001];
std::vector<std::string>kinds{}, kaku{};
char maze[1000][1000];
int sx, sy;
int gx, gy;
vector<pair<long long int, long long int>>pairs;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
bool okada = false, okada2 = false;
std::string output, output2, input, input2;
char re;
int starta, startb, enda, endb,ab;


unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int kaizyo(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}

int H, W;//はんい
bool qw = false, er = false, ty = false,ui=false;
int main() {
	cin >> a>>b>>c;
	cout << a+b+c-std::max(std::max(a, b), c) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  vector<int> P(N),p(N);
  for(int i=0;i<N;i++){cin >> S[i] >> P[i];}
  vector<tuple<string,int,int>> t(N);
  for(int i=0;i<N;i++){
    t[i]=make_tuple(S[i],-P[i],i+1);
  }
  sort(t.begin(),t.end());
  for(int i=0;i<N;i++)cout << get<2>(t[i]) << endl;
}

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

int main() {
  string s, t;
  cin >> s >> t;
 
  vector<int> a(26);
  vector<int> b(26);
  for(int i = 0; i < s.size(); i++) {
    a.at(s.at(i) - 'a')++;
  }
  sort(a.begin(), a.end());
/*  for(int i = 0; i < 26; i++) {
    cout << i << ':' << a.at(i) << endl;
  }*/
  for(int i = 0; i < t.size(); i++) {
    b.at(t.at(i) - 'a')++;
  }
  sort(b.begin(), b.end());  
/*  for(int i = 0; i < 26; i++) {
    cout << i << ':' << b.at(i) << endl;
  }*/
  
  for(int i = 0; i < 26; i++) {
    if(a.at(i) != b.at(i)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 776
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

/**
 * お遊び
 *
 * @author s-sugimoto
 */
public class Main {

	/**
	 * 隠蔽
	 */
	private Main() {
	}

	/**
	 * main
	 *
	 * @param args 起動引数
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int count = scanner.nextInt();

		Map<Integer, Boolean> resultMap = new HashMap<>();
		for (int i = 0; i < count; i++) {
			int input = scanner.nextInt();
			Boolean tmp = resultMap.get(input);
			if (tmp == null) {
				resultMap.put(input, true);
			} else {
				if (tmp) {
					resultMap.put(input, false);
				} else {
					resultMap.put(input, true);
				}
			}
		}

		System.out.println(resultMap.entrySet().stream().map(e -> e.getValue()).filter(e -> e == true).count());
	}

}


Measured memory_bytes: 63320
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll a,b,c,d;
    ll A[MAX_N];
    ll answer = 0;

    cin >> a;// >> b >> c >> d;
    //rep(i, N) cin >> A[i];
    b = a / 4;
    rep(i,b+1){
        if ((a-i*4)%7==0){cout << "Yes" << endl; return 0;}
    }

    cout << "No" << endl;

    //cout << answer << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	int a = Integer.parseInt(scan.next());
	int b = Integer.parseInt(scan.next());
	int c = Integer.parseInt(scan.next());

	System.out.println(b-a == c-b ? "YES" : "NO");
	scan.close();
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

const int MAX_H = 30, MAX_W = 30;

int H, W, K;
char c[MAX_H][MAX_W];

int c_copy[MAX_H][MAX_W];
int next_cell_row[MAX_H][MAX_W];

int solve();
int erase(int, int);
int calc_score();
int update_cell(int);
void print_cell();

int main() {
    cin >> H >> W >> K;
    REP(i, H) REP(j, W) cin >> c[i][j];
    int max_score = solve();
    PRINT(max_score);
    return 0;
}

int solve() {
    int max_score = 0;
    REP(i, H) REP(j, W) max_score = max(max_score, erase(i, j));
    return max_score;
}

int erase(int h, int w) {
    REP(i, H) REP(j, W) c_copy[i][j] = c[i][j] - '0';
    c_copy[h][w] = -1;
    int score = calc_score();
    return score;
}

int calc_score() {
    int score = 0;
    int pow2 = 1;
    update_cell(0);
    while (true) {
        // print_cell();
        int ds = update_cell(pow2);
        if (ds == 0) return score;
        score += ds;
        pow2 *= 2;
    }
}

int update_cell(int pow2) {
    int score = 0;

    // 消すマスを-1に変えつつ, スコアを計算
    REP(i, H) {
        int len_chain = 0;
        int last_num = -1;
        REP(j, W) {
            if (c_copy[i][j] == last_num) {
                len_chain++;
                if (j == W-1 && len_chain >= K && last_num != -1) {
                    score += pow2 * len_chain * last_num;
                    REP(k, len_chain) c_copy[i][j-k] = -1;
                }
            }
            else { 
                if (len_chain >= K && last_num != -1) {
                    score += pow2 * len_chain * last_num;
                    REP(k, len_chain) c_copy[i][j-k-1] = -1;
                }
                len_chain = 1;
                last_num = c_copy[i][j];
            }
        }
    }

    // 次のマスが現在のどの番地のマスになるか調べる
    for (int i = H-1; i >= 0; i--) REP(j, W) {
        if (i == H-1) next_cell_row[i][j] = H-1;
        else next_cell_row[i][j] = max(-1, next_cell_row[i+1][j] - 1);
        while (true) {
            if (next_cell_row[i][j] == -1) break;
            if (c_copy[next_cell_row[i][j]][j] != -1) break;
            next_cell_row[i][j]--;
        }
    }

    // マスを更新
    for (int i = H-1; i >= 0; i--) REP(j, W) {
        if (next_cell_row[i][j] == -1) c_copy[i][j] = -1;
        else c_copy[i][j] = c_copy[next_cell_row[i][j]][j];
    }

    return score;
}

void print_cell() {
    REP(i, 50) printf("-");
    printf("\n");
    REP(i, H) {
        REP(j, W) printf("%2d ", c_copy[i][j]);
        printf("\n");
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,h,m,minut;
  cin >>a>>b>>h>>m;
  minut=60*h+m;
  double long_t,short_t;
  long_t=minut*0.5;//度
  short_t=m*6;//度
  double degree=fabs(long_t-short_t);
  if(degree>180){degree=360-degree;}
  cout << fixed << setprecision(20);
  cout<<sqrt(a*a+b*b-2*a*b*cos(degree*3.14159265358979323846264338327950288419716939937510582097494459230781640628620899/ 180 ));
  return 0;
}

Measured memory_bytes: 4188
#include <stdio.h>

int main(void)
{
    int n;
    int h[101];

    int i, j;
    int ans;

    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%d", &h[i]);
    }

    ans = 1;

    for(i=1;i<n;i++){
        for(j=0;j<i;j++){
            if(h[i] < h[j]){
                break;
            }
        }
        if(j == i){
            ans++;
        }
    }

    printf("%d", ans);

    return 0;



    

}

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

#define F(i, a, b) for(int i=a; i<b; i++)
#define mem(arr, val) memset(arr, val, sizeof(arr))

#define MOD 1000000007
#define INF 1000000000000001
#define epsilon 1e-15

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

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int N, W;
    cin >> N >> W;
    int w[N], v[N];
    ll V = 0;
    for(int i=0; i<N; i++){
        cin >> w[i] >> v[i];
        V += (v[i]);
    }

    ll dp[N+1][V+1];
    for(int i=0; i<=N; i++)
        dp[i][0] = 0;

    for(int i=1; i<=V; i++)
        dp[0][i] = INF;

    for(int i=1; i<=N; i++){
        for(int j=1; j<=V; j++){
            if(j >= v[i-1]) dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i-1]] + w[i-1]);
            else dp[i][j] = dp[i-1][j];
        }
    }

    ll ans = 0;
    for(int i=V; i>=0; i--)
        if(dp[N][i] <= W){
           ans = i;
           break;
        }

    cout << ans << '\n';

    return 0;
   
}

Measured memory_bytes: 82432
n, k = map(int, input().split())

A = list(map(int, input().split()))

B = []
t = -1
init_sum = sum(A[0:k])

for i in range(n - k+1):
    if t < init_sum:
        B = A[i:i+k]
        t = init_sum
    if i != n - k:
        init_sum = init_sum - A[i] + A[i+k]


import collections
B = sorted(B)
C = collections.Counter(B)

D = list(C.keys())
E = list(C.values())
F = zip(D, E)
F = sorted(F)
D, E = zip(*F)

G = []
j = 0
total = 0
for i in range(max(D) + 1):
    total += i
    if D[j] == i:
        G.append(total)
        j += 1
ans = 0
k = 0
for i, j in zip(D, G):
    ans += (j/i) * E[k]
    k += 1
print(ans)

Measured memory_bytes: 135880
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;


int main()
{
  ll n,a[200010],number[200010]={0};
  ll sum=0;
  cin>>n;
  rep(i,n){
    cin>>a[i];
    sum+=number[a[i]];
    number[a[i]]++;
  }


  rep(i,n)cout<<sum-(number[a[i]]-1)<<endl;
  return 0;
}


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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n;
    cin >> n;
    vector<int> a(n);

    for (int i=0; i<n-1; i++) {
        int x; cin >> x;
        a[x-1]++;
    }
    for (int e : a) {
        cout << e << "\n";
    }
}


Measured memory_bytes: 3984
import math
from math import gcd,pi
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    l = [1]
    ans = []
    for i in range(2,10**4):
        l.append(l[i-2]+i)
    while True:
        if n == 0:
            break
        for i,k in enumerate(l):
            if n <= k:
                if i == 0:
                    a = k
                else:
                    a = k - l[i-1]
                ans.append(a)
                n -= a
                break
    for i in ans:
        print(i)

if __name__=="__main__":
    main()


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

string S;
deque<char> D;


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	FORR(c,S) D.push_back(c);
	
	int ret=0;
	while(D.size()>=2) {
		if(D.front()==D.back()) {
			D.pop_back();
			D.pop_front();
		}
		else if(D.front()=='x') {
			ret++;
			D.pop_front();
		}
		else if(D.back()=='x') {
			ret++;
			D.pop_back();
		}
		else {
			return _P("-1\n");
		}
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

s = input()
t = input()

c = N

for i in range(N):
    f = 1
    for j in range(N-i):
        if not s[i+j]==t[j]:
            f = -1
    if f>0:
        K = c
        break
    else:
        c = c-1
else:
    K=0

print(2*N-K)

Measured memory_bytes: 3060