akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt();
		int red[][] = new int[n][2];
		int blue[][] = new int[n][2];
		for(int i=0;i<n;i++) {
			red[i][0] = fs.nextInt();
			red[i][1] = fs.nextInt();
		}
		for(int i=0;i<n;i++) {
			blue[i][0] = fs.nextInt();
			blue[i][1] = fs.nextInt();
		}
		
		Arrays.sort(blue, (b1,b2)->b1[0] - b2[0]);
		Arrays.sort(red, (b1,b2)->b1[0] - b2[0]);
		TreeSet<Integer> ts = new TreeSet<>();
		
		int ans = 0;
		int redp = 0;
		for(int i=0;i<n;i++) {
			int x = blue[i][0];
			int y = blue[i][1];
			while(redp<n&&red[redp][0]<x) {
				ts.add(red[redp][1]);
				redp++;
			}
			if(ts.lower(y)==null)continue;
			ts.remove(ts.lower(y));
			ans++;
		}
		System.out.println(ans);
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

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

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

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

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

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

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

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

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

Measured memory_bytes: 27732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;
const int N = 2e3 + 5;

ll n,dp[N][N];
vector<pair<ll,int> >V(n);

ll DP(int L,int R){
	if(R<L) return 0;
	if(dp[L][R]!=-1) return dp[L][R];
	int i=L+n-1-R;
	return dp[L][R]=max(V[i].first*abs(V[i].second-L)+DP(L+1,R),V[i].first*abs(V[i].second-R)+DP(L,R-1));
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int i=0;i<n;i++){int x;cin>>x; V.push_back({x,i});}
	sort(V.rbegin(),V.rend());
	memset(dp,-1,sizeof(dp));
	cout<<DP(0,n-1);
	return 0;
}

Measured memory_bytes: 35224
#include<iostream>
using namespace std;
int n, p, t;
int main() {
	cin >> t;
	for (int i = 0; i < t; i++) {
		cin >> n >> p; n--;
		if (n % 2 == 0)cout << p + 127 * n << endl;
		else { cout << (127 - p) + 127 * n << endl; }
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n, k;
  cin >> n >> k;
  ll a[n];
  ll sum=0;
  for(ll i=0;i<n;i++){	cin >> a[i];}
  sort(a,a+n);
  for(int i=0;i<k;i++)	sum+=a[i];
  cout << sum << endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define ll             long long int
#define lb             lower_bound
#define ub             upper_bound
#define fi             first
#define mp             make_pair
#define vll            vector<ll>
#define se             second
#define sz             size()
#define mod            1000000007
#define endl           "\n"
#define fast           ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define allr(v)        v.rbegin(),v.rend()
#define inp(V,n)      for(int i=0;i<n;i++){cin >> V[i];}
#define oup(V,n)     {for(int i=0;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
using namespace std;
ll factorial(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll gcd(ll a, ll b)
{
    if (a == 0)
      return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
   return (a*b)/gcd(a, b);
}
bool sortByVal(const pair<double,double> &a,
               const pair<double,double> &b)
{
    if(a.fi==b.fi)
    {
    return (a.second >b.second);
    }
    else
        return (a.fi<b.fi);
}

int main()
{
     fast;
     int q=1;
   // cin>>q;
     while(q--)
    {
     ll n,i,j,k,m,sum=0,ans=0,a=0,b=0,c=0,d=0,e;
       cin>>n>>k;
       vll v(n);
       inp(v,n);
       sort(all(v));
       for(i=0;i<k;i++)
       {
           sum+=v[i];
       }
   cout<<sum<<endl;

    }
   return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	int n;
	lint k; scanf("%d%lld",&n,&k);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	vector<int> next(n);
	{
		vector<vector<int>> Pos(2e5+1);
		rep(i,n) Pos[a[i]].emplace_back(i);
		rep(x,2e5+1) rep(i,Pos[x].size()) next[Pos[x][i]]=Pos[x][(i+1)%Pos[x].size()];
	}

	int per=1;
	{
		int p=0;
		do{
			if(p>=next[p]) per++;
			p=(next[p]+1)%n;
		}while(p!=0);
	}

	if(k%per==0) return 0;

	k=(k-1)%per;

	int p=0;
	while(k>0){
		if(p>=next[p]) k--;
		p=(next[p]+1)%n;
	}

	vector<int> ans;
	while(p<n){
		if(p>=next[p]) ans.emplace_back(a[p]), p++;
		else           p=next[p]+1;
	}
	rep(i,ans.size()) printf("%d%c",ans[i],i+1<ans.size()?' ':'\n');

	return 0;
}


Measured memory_bytes: 12800
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<vector<int> > vvi;
typedef vector<int> vi;
typedef vector<string> vs;
struct node {
	int key;
	node *prev, *next;
};

node *nil;
void init() {
	nil = (node*)malloc(sizeof(node));
	nil->next = nil;
	nil->prev = nil;
}

void insert(int val) {
	node* x = (node *)malloc(sizeof(node));
	x->key = val;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}
node* search(int val) {
	node* cur = nil->next;
	while (cur!=nil) {
		if (cur->key==val) {
			break;
		}
		cur = cur->next;
	}
	return cur;
}
void del(int val) {
	node* x = search(val);
	if (x != nil) {
		x->prev->next = x->next;
		x->next->prev = x -> prev;
		free(x);
	}
}
void deleteFirst() {
	node* x = nil->next;
	if (x != nil) {
		x->prev->next = x->next;
		x->next->prev = x -> prev;
		free(x);
	}
}
void deleteLast() {
	node* x = nil->prev;
	if (x != nil) {
		x->prev->next = x->next;
		x->next->prev = x -> prev;
		free(x);
	}
}
int main() {
	init();
	int N;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		char type[30];
		scanf("%s",&type);
		if (strcmp(type, "insert")==0) {
			int val;
			scanf("%d", &val);
			insert(val);
		}
		else if (strcmp(type, "deleteFirst")==0) {
			deleteFirst();
		}
		else if (strcmp(type,"deleteLast")==0) {
			deleteLast();
		}
		else {
			int val;
			scanf("%d", &val);
			del(val);
		}
	}
	node *temp = nil;
	while (temp->next!=nil)
	{
		if (temp != nil)cout << " ";
		temp=temp->next;
		cout << (temp->key);
	}
	cout << endl;
};


Measured memory_bytes: 34424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007
 
int n,k,l;
 
const int MAX_N=200001;
 
int par1[MAX_N]; //　親
int rank1[MAX_N]; // 木の深さ
int par2[MAX_N];
int rank2[MAX_N];
 
 
// ｎ要素で初期化
void init(){
  for(int i=0;i<n;i++){
    par1[i]=par2[i]=i;
    rank1[i]=rank2[i]=0;
  }
}
 
// 木の根を求める
int find(int x, bool flag){
  if(flag){
    if (par1[x] == x){
      return x;
    }else{
      return par1[x] = find(par1[x],flag);
    }
  }else{
    if(par2[x]==x){
      return x;
    }else{
      return par2[x]=find(par2[x],flag);
    }
  }
}
 
// ｘとｙの属する集合を併合
void unite(int x, int y, bool flag){
  x = find(x,flag);
  y = find(y,flag);
  if (x == y) return;
  if(flag){
    if (rank1[x] < rank1[y]){
      par1[x] = y;
    }else{
      par1[y] = x;
      if (rank1[x] == rank1[y]) rank1[x]++;
    }
  }else{
    if(rank2[x]<rank2[y]){
      par2[x]=y;
    }else{
      par2[y]=x;
      if(rank2[x]==rank2[y]) rank2[x]++;
    }
  }
}
 
// ｘとｙが同じ集合に属するかどうか
bool same(int x, int y, bool flag){
  return find(x,flag) == find(y,flag);
}
 
 
int main(){
  cin>>n>>k>>l;
  init();
  for(int i=0;i<k;i++){
    int p,q;
    cin>>p>>q;
    unite(p-1,q-1,1);
  }
  for(int i=0;i<l;i++){
    int p,q;
    cin>>p>>q;
    unite(p-1,q-1,0);
  }
  //for(int i=1;i<=n;i++) cout<<par1[i]<<" "<<par2[i]<<endl;
  int num[n]={};
  vector<pair<pair<int,int>, int>> v;
  for(int i=0;i<n;i++){
    v.push_back({{find(i,1),find(i,0)}, i});
  }
  sort(v.begin(),v.end());
  int count=1, ind=0;
  for(int i=1;i<n;i++){
    if(v[i].first==v[i-1].first){
      count++;
    }else{
      for(int j=ind;j<i;j++){
        num[v[j].second]+=count;
      }
      ind=i;
      count=1;
    }
  }
  for(int i=ind;i<n;i++){
    num[v[i].second]+=count;
  }
  for(int i=0;i<n-1;i++){
    cout<<num[i]<<" ";
  }
  cout<<num[n-1]<<endl;
  return 0;
}

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

using namespace std;
int n,T,c[2000],t[2000];
int main() {
  cin>>n>>T; int cm=1e9;
  for (int i=1; i<=n; ++i) {
    cin>>c[i]>>t[i];
    if (t[i]<=T && c[i]<cm) cm=c[i];
  }
  if (cm==1e9) cout<<"TLE"<<endl;
  else cout<<cm<<endl;
}

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

void run(void){
  char *x=(char *)malloc(sizeof(char)*(200000+1));
  scanf("%s",x);
  char *s=(char *)malloc(sizeof(char)*(200000+1));
  int top=0;
  int n=0;
  while(x[n]!='\0'){
    s[top++]=x[n++];
    if(top>1 && s[top-1]=='T' && s[top-2]=='S') top-=2;
  }
  printf("%d\n",top);
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 512
from sys import stdin
from collections import deque


class BFS():
    def __init__(self, con, val=None):
        # 隣接リスト表現
        self.con = con
        self.val = val
        self.N = len(self.con)
        # 1つ前の部屋(1-indexed)
        self.dist = [-1]*self.N
        self.que = deque()

        # 初期条件(0-indexed)
        self.dist[0] = 0
        self.que.append(0)

    def bfs(self):
        while self.que:
            v = self.que.popleft()
            for next_v in self.con[v]:
                if self.dist[next_v] != -1:
                    continue
                self.dist[next_v] = v+1
                self.que.append(next_v)


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, M = list(map(int,_in[0].split(' ')))  # type:list(int)
    A_B_arr = []
    for i in range(M):
        _ = list(map(int,_in[i+1].split(' ')))  # type:list(int)
        A_B_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    con = [[] for i in range(N)]
    for A,B in A_B_arr:
        A -= 1
        B -= 1
        con[A].append(B)
        con[B].append(A)

    bfs = BFS(con)
    bfs.bfs()
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    if -1 in bfs.dist[1:]:
        print('No')
    else:
        print('Yes')
        for _ in bfs.dist[1:]:
            print(_)


Measured memory_bytes: 149612
N, L = map(int, input().split())
applepye = 0
eat = 0
if N + L <= 0:
    eat = L + N - 1
    for i in range(L, L + N):
        applepye += i
    print(applepye - eat)
elif N + L > 0 and L >= 0:
    eat = L
    for i in range(L, L + N):
        applepye += i
    print(applepye - eat)
else:
    eat = 0
    for i in range(L, L + N):
        applepye += i
    print(applepye - eat)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int r,d;
  cin>>r>>d;
  int x;
  cin>>x;
  int a=0;
  for (int i=1;i<=10;i++){
    a=r*x-d;
    cout<<a<<endl;
    x=a;
  }
}

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

int main(){
    int a,b;
    cin >> a ;
    if(a<1200) cout << "ABC" << endl;
    else if(a<2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define ull unsigned long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) (int)(x).size()
using namespace std;

#define N 100007

int n, e = inf;

ll res;

VPII G[N];

int sub[N];
int max_sub[N];
int p[N];

void dfs(int v)
{
	sub[v] = 1;

	for(auto it:G[v])
	{
		if(!sub[it.st])
		{
			p[it.st] = v;
			dfs(it.st);
			res += 2ll*min(sub[it.st], n-sub[it.st])*it.nd;
			max_sub[v] = max(max_sub[v], sub[it.st]);
			sub[v] += sub[it.st];
		}
	}

	for(auto it:G[v])
	{
		if(it.st!=p[v] && 2*max_sub[it.st]==n && 2*max_sub[v]==n)
			e = it.nd;
	}

	max_sub[v] = max(max_sub[v], n-sub[v]);
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n;

	for(int i = 1; i < n; ++i)
	{
		int a, b, c;
		cin >> a >> b >> c;
		G[a].eb(b, c);
		G[b].eb(a, c);
	}

	dfs(1);

	if(e==inf)
	{
		for(int i = 1; i <= n; ++i)
		{
			if(2*max_sub[i]<n)
			{
				for(auto it:G[i])
					e = min(e, it.nd);
			}
		}
	}

	cout << res-e;
}


Measured memory_bytes: 14976
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

a,b=map(int,input().split())
if a*b<0:
    print('Zero')
elif a<0 and ((b>0 and a%2) or (b<0 and (b-a+1)%2)):
    print('Negative')
else:
    print('Positive')

Measured memory_bytes: 61552
#include<stdio.h>

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

  scanf("%d %d %d", &a, &b, &c);
  while(0>a || 0>b || 0>c || a>100 || b>100 || c>100){
    printf("??????????????\??????????????????\n");
    scanf("%d %d %d", &a, &b, &c);
  }
  
  if(a<b && b<c && a<c){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  return 0;
}

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

int main(){
    int N;
    string S;
    cin>>N>>S;
    stack<char> st;
    st.push('N');

    for(int i=0; i<N; i++){
        char pr =  st.top();
        if((S[i] == ')' && pr == '(')){
            st.pop();
        }
        else{
            st.push(S[i]);
        }
    }

    map<char,int> cnt;
    while(!st.empty()){
        char t = st.top();
        st.pop();
        cnt[t]++;
    }

    string ans = "";
    for(int i=0; i<cnt[')']; i++) ans += '(';
    ans += S;
    for(int i=0; i<cnt['(']; i++) ans += ')';

    cout<<ans<<endl;
}

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

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int n;
  cin >> n;
  set<int> a;
  vector<int> cnt(1000005);
  rep(i, n) {
    int x;
    cin >> x;
    a.insert(x);
    ++cnt[x];
  }

  vector<int> f(1000005, 0);
  for (int i = 1; i <= 1e6; ++i) {
    if (a.find(i) == a.end()) continue;
    if (f[i] == 0) {
      for (int j = 2 * i; j <= 1e6; j += i) {
        f[j] = 1;
      }
    }
  }

  int ans = 0;
  for (auto u : a) {
    if (f[u] == 0) {
      if (cnt[u] == 1) ++ans;
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 20324
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 5100
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)


//計算量はO(V*E)
struct edge{
  int from,to,cost;
};

edge es[110000]; //辺

ll d[110000]; //最短距離

int V,E; //Vは頂点数，Eは辺数
bool ans[2600];

//s番目の頂点から各頂点への最短距離を求める
void shortest_path(int s){
  for(int i=0;i<V;i++) d[i]=INF;
  d[s]=0;
  int count=0;
  while(true){
    bool update=false;
    for(int i=0;i<E;i++){

      edge e=es[i];
        //cout<<e.from<<endl;

      if(count>=2*V && ans[e.from]) ans[e.to]=true; 
      if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost){
          if(count>=2*V){
              ans[e.to]=true;
          }
        d[e.to]=d[e.from]+e.cost;
        update=true;
      }
    }
    if(!update) break;
    if(count>=3*V+2) break;
    count++;
  }

}


int main(){
    for(int i=0;i<2600;i++) ans[i]=false;
    int c;
    cin>>V>>E>>c;
    for(int i=0;i<E;i++){
        int A,B,C;
        cin>>A>>B>>C;
        A--; B--;

        es[i].from=A;
        es[i].to=B;
        es[i].cost=(C-c)*(-1);
    }
    shortest_path(0);
    if(ans[V-1]) cout<<-1<<endl;
    else cout<<max(d[V-1]*(-1),0LL)<<endl;
}



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

using namespace std;

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

#define REP(i,n) for(int(i)=0;(i)<(int)(n);(i)++)

using namespace std;

char s[1110000];
int lo[1100000];
int hi[1100000];

int main() {
	scanf("%s", s);
	int n = strlen(s);

	long long sm = 0;
	int la = 0;

	lo[n] = 0;

	for (int i = n-1; i >= 0; i--) {
		if (s[i] == '<') {
			lo[i] = 0;
		}
		else {
			lo[i] = max(0, lo[i+1]+1);
		}
	}

	int cur = lo[0];
	sm += cur;

	for (int i = 0; i < n; i++) {
		if (s[i] == '<') {
			cur = max(cur+1,lo[i+1]);
		}
		if (s[i] == '>') {
			cur = min(cur-1, lo[i+1]);
		}
		sm += cur;
	}
	printf("%lld\n", sm);
}

Measured memory_bytes: 4992
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];


int main()
{
    ll n,i,j,cc=0;
    map<string,ll>check;
    cin>>n;
    while(n--){
        string str;cin>>str;
        check[str]++;
    }
    cout<<check.size()<<endl;
return 0;
}


Measured memory_bytes: 23916
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<cstdio>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
    long int n;
    cin >> n;
    vector<string> s(n);

    for(int i = 0; i < n; i++){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
        //cout << s[i] << endl;
    }

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

    /*
    cout << endl;
    for(int i = 0; i < n; i++){
        cout << s[i] << endl;
    }
    */
    

    int j = 0;
    long int count = 0;
    int flag = 0;
    long int ans = 0;
    for(int i = 0; i < n-1; i++){
        if(s[i] == s[i+1]){
            count++;
            flag = 1;
        }
        else {
            /*
            if(flag == 1){
                count++;
                flag = 0;
            }
            */
            flag = 0;
            count = 0;
        }

        if(flag == 1){
            ans += count;
        }
        //cout << ans << endl;
    /*
        if(i == n-2){
            if(s[i] == s[i+1]){
                count++;
            }
        }
    */
        
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
 

int n,m,l;
struct edge{int to;int dd;int ee;};

int main(){
    while(cin >> n >> m >> l,n){
        vector<int> a(m),b(m),d(m),e(m);
        vector<vector<edge>> G(n+1);
        for (int i = 0; i < m; i++) {
            cin >> a[i] >> b[i] >> d[i] >> e[i];
            a[i]--,b[i]--;
            G[a[i]].pb({b[i],d[i],e[i]});
            G[b[i]].pb({a[i],d[i],e[i]});
        }
        vector<vector<int>> dp(n+1,vector<int> (l+1,INF));
        dp[0][0]=0;
        priority_queue<pair<int,P>,vector<pair<int,P>>,greater<pair<int,P>>> pq;
        pq.push({0,{0,0}});
        while(!pq.empty()){
            int v=pq.top().second.second;
            int ll=pq.top().second.first;
            int c=pq.top().first;
            pq.pop();
            if(dp[v][ll]<c) continue;
            for (int i = 0; i < G[v].size(); i++) {
                edge e=G[v][i];
                int to=e.to;
                int dd=e.dd;
                int ee=e.ee;
                if(dp[to][ll]>dp[v][ll]+ee){
                    dp[to][ll]=dp[v][ll]+ee;
                    pq.push({dp[to][ll],{ll,to}});
                }
                if(ll+dd<=l&&dp[to][ll+dd]>dp[v][ll]){
                    dp[to][ll+dd]=dp[v][ll];
                    pq.push({dp[to][ll+dd],{ll+dd,to}});
                }
            }
        }
        int ans = INF;
        for (int i = 0; i <= l; i++) {
            ans = min(ans,dp[n-1][i]);
        }
        cout << ans << endl;
    }
    return 0;
}




Measured memory_bytes: 3704
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (a, b, c) = (v[0], v[1], v[2]);
    if (a == b && b != c) || (a == c && b != c) || (c == b && b != a) {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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


void solve(long long A, long long B, long long T){
  cout << (T/A) * B << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long T;
    scanf("%lld",&T);
    solve(A, B, T);
    return 0;
}


Measured memory_bytes: 256
S = input()
X, Y = map(int, input().split())

A = [0]
for s in S:
    if s == 'T':
        A.append(0)
    else:
        A[-1] += 1

B = [n for n in A[1:: 2]]
X -= A[0]
A = [n for n in A[2:: 2]]

def canGo(nums, g):
    if not nums:
        return g == 0

    bias = sum(nums) + 10
    g += bias
    if g < 0:
        return False

    dp = (1 << bias)

    for n in nums:
        dp = (dp << n) | (dp >> n)
    return (dp & (1 << g)) > 0

if canGo(A, X) and canGo(B, Y):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define rep(i,N) for(ll i=0; i<N; i++)
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll N_MAX = 100000;

int main(){
    int a, b; cin >> a >> b;
    cout << max(a - 2*b, 0) << endl;
}

Measured memory_bytes: 256
"""
    こんにちは。これはクシャルです
    
    Author : thekushalghosh (クシャル)
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################

def solve():
    s = insr()
    if s == "Sunny":
        q = "Cloudy"
    elif s == "Cloudy":
        q = "Rainy"
    else:
        q = "Sunny"
    print(q)
    
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 
#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1],1
    return(q)
 
def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97],1
    return(q)

def factors(n):
    q = []
    for i in range(1,int(n ** 0.5) + 1):
        if n % i == 0: q.append(i); q.append(n // i)
    return(list(sorted(list(set(q)))))

def prime_factors(n):
    q = []
    while n % 2 == 0: q.append(2); n = n // 2
    for i in range(3,int(n ** 0.5) + 1,2):
        while n % i == 0: q.append(i); n = n // i
    if n > 2: q.append(n)
    return(list(sorted(q)))

#-----------------------------------------------------------------------#
        
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
    
    
    
main()

Measured memory_bytes: 62888
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>//for the sake of memset
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;

int main(){
	string str;
	cin >> str;
	int K;
	cin >> K;
	for(int i = 0;i < str.length();i++){
		int sub = 26 - (str[i] - 'a');
		if(sub != 26){
			if(K >= sub){
				K -= sub;
				str[i] = 'a';
			}
		}
		if(i == str.length() - 1){
			str[i] += K % 26;
		}
	}
	cout << str <<endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
	string a;
	for(int i=0;i<3;i++){
		string s;
		cin>>s;
		a[i]=s[i];
	}
	for(int i=0;i<3;i++){
		cout<<a[i];
	} 
	return 0;
} 

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

using namespace std;

using ll = long long;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

template<class T>
void print(vector<T> a) {
  cout << "[ ";
  REP(i, a.size()) cout << a[i] << " ";
  cout << "]" << endl;
}

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

int main() {
  int input(n);
  vector<int> p(n), q(n);
  REP(i, n) cin >> p[i];
  REP(i, n) cin >> q[i];

  vector<int> index(n);
  REP(i, n) index[i] = i + 1;

  int a, b, cnt = 0;
  do {
    cnt++;
    if (index == p) {
      a = cnt;
    }
    if (index == q) {
      b = cnt;
    }
  } while (next_permutation(index.begin(), index.end()));
  print(abs(a - b));
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


int main() {
    int A, B;
    char op;
    cin >> A >> op >> B;
    if(op=='+') cout << A + B << endl;
    else cout << A - B << endl;
}


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

if k%2==1:
  a=n//k
  print(a**3)
  
else:
  half=k//2
  if half>k:
    print(0)
  else:
    ans=0
    while half<=n:
      ans+=1
      half+=k
      
    a=n//k
    print(a**3+ans**3)

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


void solve(long long X, long long Y, long long Z){
    X-= Z;
    cout << X / (Y+Z) << endl;
}

int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    long long Z;
    scanf("%lld",&Z);
    solve(X, Y, Z);
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * dp[i] 表示走到i点的方案数
 *
 * 因为只能在区间当中取数，同时对于每一个区间[a,b] , dp[b] = dp[i-b] + dp[i-b+1] + ...... + dp[i-a] （因为能取的数只有a~b）
 *
 * 因此转移方程为：
 *
 * i == 0 时 dp[i] = 1
 *
 * a[0] > i > 0
 *
 * dp[i] = 0;
 *
 * b[j] >= i >= a[j] 时：
 *
 * dp[i] = dp[i-a[j]] + ...... + dp[max(0,i-b[j])]
 *
 * 其他情况
 *
 * dp[i] = dp[i-1]
 *
 * Created by enpingkuang on 2020/9/19 7:53 下午
 */
public class Main {
    private static int MOD = 998244353;
    private static long[] dp = new long[200005];
    private static long[] sum = new long[200005];

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] l = new int[200005];
        int[] r = new int[200005];
        for(int i = 0;i<k;i++){
             l[i] = scanner.nextInt();
             r[i] = scanner.nextInt();
        }
        dp[0] = 1;
        sum[0] = 1;
        for(int i=1;i<n;i++) {
            for(int j = 0;j<k;j++){
                if(i >= l[j]){
                    long flag = i-r[j]-1 < 0?0:sum[i-r[j]-1];
                    dp[i] = ((dp[i] + sum[i-l[j]] - flag)%MOD + MOD)%MOD;
                }
            }
            sum[i] = (sum[i-1] + dp[i])%MOD;
        }
        System.out.println(dp[n-1]);
    }
}


Measured memory_bytes: 41300
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    string s1, s2; cin >> s1 >> s2;
    s1 += s2;

    int ab = stoi(s1);

    for(int i=1; i<ab; i++){
        if(ab == i*i){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}


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

int main()
{
  int n,f;
  f=0;
  cin>>n;
  for(int i=0;i<=25;i++)
  {
    for(int j=0;j<=14;j++)
    {
      if(i*4+j*7==n)
      {
        f=1;
        break;
      }
    }
  }
  if(f==1)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 3528
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <functional>
# include <utility>
# include <queue>
# include <stack>
# define MOD 1000000007
# define INF 2000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
std::vector<bool> IsPrime;

int main() {
	long long  counter = 0, maxi = -1, mini = INF, pass = 0;
	//new
	ll n, m;
	char gridA[50][50], gridB[50][50];
	rep(i, 50) {
		rep(j, 50) {
			gridA[i][j] = ' ';
			gridB[i][j] = ' ';
		}
	}
	cin >> n >> m;
	rep(i, n) {
		rep(j, n) {
			cin >> gridA[i][j];
		}
	}
	rep(i, m) {
		rep(j, m) {
			cin >> gridB[i][j];
		}
	}
	bool ans=false;
	for (ll j = 0; j < n - m + 1; j++) {
		for (ll i = 0; i < n - m + 1; i++) {
			counter = 0;
			rep(x, m) {
				rep(y, m) {
					if (gridA[i + x][j + y] == gridB[x][y]) {
						counter++;
					}
				}
			}
			if (m*m==counter)ans = true;
		}
	}
	if (ans)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    string str;
    cin >> str;
    int n = str.length();
    int nSum = 0;
    for(int i = 0; i < n; i++){
        int k = str[i] - '0';
        nSum += k;
    }
    
    if(nSum % 9 == 0){
        printf("Yes");
    }
    else {
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 3380
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, i, j, k;
    long long int sum = 0;
    scanf("%d", &n);
    scanf("%d", &k);
    int a[n];
    for (i=0; i<n; i++) scanf("%d", &a[i]);
    sort(a, a+n);
    for (i=0; i<n-k; i++) sum+= (long long int)a[i];
    printf("%lld", sum);
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n; cin >> n;
	lf ans=0.0;
	rep(i, n){
		lf x; string u;
		cin >> x >> u;
		if (u=="JPY"){
			ans+=x;
		}else{
			ans+=380000.0*x;
		}
	}
	cout << setp(8) << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
    int a,b;
    while(cin>>a>>b){
        if(abs(a-b)>=2)
            cout<<0<<endl;
        else if(a==b){
            long long int sum=1;
            for(int i=1;i<=a;i++){
                sum*=i;
                sum=sum%(1000000000+7);
            }
            sum=sum*sum*2%(1000000000+7);
            cout<<sum<<endl;
        }
        else{
            long long int sum=1;
            long long int summ=1;
            for(int i=1;i<=max(a,b);i++){
                sum*=i;
                sum=sum%(1000000000+7);
            }
            for(int i=1;i<=min(a,b);i++){
                summ*=i;
                summ=summ%(1000000000+7);
            }
            sum=sum*summ%(1000000000+7);
            cout<<sum<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
X,K,D = map(int,input().split())

if abs(X) > K * D:
    if X >= 0:
        print(X - K * D)
    else:
        print(abs(X + K * D))
else:
    loop = abs(X) // D
    nok = K - loop
    if X >= 0:
        tmp = X - (loop * D)
        if nok % 2 == 0:
            print(tmp)
        else:
            print(abs(tmp - D))
    else:
        tmp = X + (loop * D)
        if nok % 2 == 0:
            print(abs(tmp))
        else:
            print(abs(tmp + D))

Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin >> n >> s;
  int ans = 1;
  for (int i=1; i<n; i++){
    if (s[i-1]==s[i]){
      continue;
    }
    else ans++;
  }
  cout << ans;
  return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const int N = 2e5+23;

int a[N];

void solve() {
	int n; scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", a+i);
	}
	if (n%2) {
		for (int i = n-n%2; i >= 0; i-=2) printf("%d ", a[i]);
		for (int i = 1; i < n; i+=2) printf("%d ", a[i]);
	} else {
		for (int i = n-!(n%2); i > 0; i-=2) printf("%d ", a[i]);
		for (int i = 0; i < n; i+=2) printf("%d ", a[i]);
	}
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 2944
//“Make it work, make it right, make it fast.” – Kent Beck
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dd;
const int siz = 1e6 + 5;
const int MOD = 1e9 + 7;
#define endl '\n'
#define deb(x) cout << #x << " = " << x << endl;
const ll INF = 1e16;

vector<ll> a;
ll n, k;
bool check(ll x) {
  ll maxi = 0;
  for(ll i = 0 ; i < n; i++) {
    if(a[i] <= x) continue;
    maxi += (a[i]+ x -1)/x;
    maxi--;
  }
  return maxi <= k;
}

void solve() {
  cin >> n >> k;
  ll l = 1, h = INF;
  a = vector<ll> (n);
  for(ll &i : a) cin >> i;
  ll count = 0;
  while(l <= h) {
    ll mid = (l+h)/2;
    if(check(mid)) {
      count = mid;
      h = mid-1;
    } else {
      l = mid+1;
    }
  }
  cout << count << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed << setprecision(10);
  int t = 1;
  // cin >> t;
  for(int tt = 1; tt <= t; tt++) {
    //cout << "Case #" << tt << ": ";
    solve();
  }
  return 0;
}  

Measured memory_bytes: 4760
#include <stdio.h>

int main(void) {
	long a,b,c;
	scanf("%ld\n",&a);
	b=0;
	c=1;
	while(1){
		if(b==a){break;}
		b=b+1;
		c=c*b;
	}
	printf("%ld\n",c);
	return 0;
}

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

int main() {
  long N,K;cin>>N>>K;
  vector<long> A(N);
  for(int i=0;i<N;i++) cin>>A.at(i);
  sort(A.begin(),A.end());
  long count;
  long left=1;
  long right=A.at(N-1);
  while(left<right){
    count=0;
    long X=(left+right)/2;
    for(int i=0;i<N;i++){
      /*count += ceil(A.at(i)/X);
      if(ceil(A.at(i)/X)*X==A.at(i)) count--;*/
      count+= A.at(i)/X;
      if(A.at(i)%X==0) count--;
    }
    if(count>K) left=X+1;
    else right=X;
  }
  cout<<right<<endl;
}



Measured memory_bytes: 4756
#include <bits/stdc++.h>
#include <algorithm>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long 
#define pb push_back
using namespace std;

void solve(){
    ll a,b;
    cin >> a >> b;
    cout<<a*b;
}

int main() {
    fast;
    solve();
	//ll t; cin >> t; while(t--){ solve(); }
	return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef long long ll; 
typedef map<ll,int>::iterator M;
map <ll,int> r;

void W(int a,int b){
  M it=r.begin();
  ll pre=0;
  while(it!=r.end()){
    if(it->s==-1){
      if((it->f)-pre>=b){
	r[pre+b]=a;
	return;
      }
      it->s=a;
      b-=((it->f)-pre);
    }
    pre=it->f;
    it++;
  }
}

void D(int a){
  M it=r.begin();
  while(it!=r.end()){
    if(it->s==a)it->s=-1;
    it++;
  }
}

int R(ll a){
  M it=r.begin();
  while(it!=r.end()){
    if((it->f)>=a){
      return it->s;
    }
    it++;
  }
  return -1;
}

int main(){
  int n;
  while(cin>>n,n){
    r.clear();
    r[1000000000000000LL]=-1;

    while(n--){
      char c;
      int a,b;
      cin>>c;
      if(c=='W'){
	cin>>a>>b;
	W(a,b);

      }
      else if(c=='D'){
	cin>>a;
	D(a);
      }
      else if(c=='R'){
	cin>>a;
	cout<<R(a+1)<<endl;
      }
    }
    /*
    M it=r.begin();
    while(it!=r.end()){
    cout <<it->f<<" "<<it->s<<endl;
      it++;
      }*/
    cout <<endl;
  }
  return 0;
}

Measured memory_bytes: 1480
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    double[] array = new double[n];
    double ave = 0;
    int sum = 0;
    for(int i = 0; i < n; i++){
      array[i] = sc.nextDouble();
      ave += array[i];
    }
    ave = (ave/array.length);
    if((ave*10)%10 >= 5){
      ave++;
    }
    int avera = (int) ave;
    for(int i = 0; i < array.length; i++){
      sum += Math.pow(Math.abs(array[i]-avera),2);
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 25172
N=int(input())
A=list(map(int,input().split()))
A0=0
A4=0
for i in range(N):
    if A[i]%2==1:
        A0+=1
    elif A[i]%4==0:
        A4+=1
if A4>=A0:
    print("Yes")
elif A4+1==A0 and A4+A0==N:
    print("Yes")
else:
    print("No")

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

using namespace std;

bool exists(int x, vector<int> &v){
  for(int e : v){
    if(e == x) return true;
  }
  return false;
}

int main(){
  int n;
  cin >> n;
  
  map<int, int> a;
  for(int i = 0; i < n; i++){
    int in;
    cin >> in;
    if(a.count(in) == 0){
      a[in] = 1;
    }else{
      a[in]++;
    }
  }
  
  bool result = false;
  
  if(a.size() == 3){
    int i = 0;
    int c[3];
    int x = 0;
    for(pair<int, int> e : a){
      x ^= e.first;
      c[i] = e.second;
      i++;
    }
    if(x == 0 && c[0] == c[1] && c[1] == c[2]){
      result = true;
    }
  }else if(n % 3 == 0 && a.size() == 2 && a[0] == n / 3){
    result = true;
  }else if(a[0] == n){
    result = true;
  }
  
  cout << (result ? "Yes" : "No") << '\n';
  
  return 0;
}

Measured memory_bytes: 3840
input1  = input().split()
input2  = input().split()
input3  = input().split()
N = int(input())

A = [input1, input2, input3]


for i in range(N):
  n = input()
  A[0] = ['0' if j == n else j for j in A[0]]
  A[1] = ['0' if j == n else j for j in A[1]]
  A[2] = ['0' if j == n else j for j in A[2]]



ans = 'No'
if A[1][1] == A[2][2] == A[0][0] == "0":
  ans = "Yes"

if A[1][1] == A[2][0] == A[0][2] == "0":
  ans = "Yes"
  
for i in range(3):
  if A[i] == ['0','0','0']:
    ans = "Yes"
  if A[0][i] == A[1][i] == A[2][i] == "0":
    ans ='Yes'
  
print(ans)
  

Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<string>

using namespace std;

int main(){
	int x[5], ans;
  
  for(int i=0;i<5;i++){
  	cin>>x[i];
  }
  
  ans=1;
  
  for(int i=0;i<5;i++){
  	if(x[i]==0){
    	ans+=i;
    }
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned long;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

    UL dp[10001];

    void Solve() {
        rep(i, 10001) dp[i] = 2000000000;
        dp[0] = 0;
        UL N, W; cin >> N >> W;
        rep(i, N) {
            UL v, w; cin >> v >> w;
            for (UL t = 10000; t >= v; t--) {
                dp[t] = min(dp[t], dp[t - v] + w);
            }
        }
        UL ans = 0;
        rep(i, 10001) if (dp[i] <= W) ans = i;
        cout << ans << endl;
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    cout << fixed << setprecision(10);
    p->Solve();
    return 0;
}



Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#include<math.h>
#define ll long long
#define ld long double
#define all(a) (a.begin(),a.end())
#define Summon_Tourist ios::sync_with_stdio(false);cin.tie(0);
ll gcd(ll a , ll b) { return b==0?a: gcd( b, a%b); }
ll lcm(ll a , ll b) { return a/gcd(a,b) * b ; }
ll inf = 1e15 + 1;
ll modexp( ll base ,ll power)
 {
     if( power == 0  ) return 1;
     if( power & 1) return base*modexp( base , power-1 )%inf;
     return modexp(base*base%inf,power/2);
 }
 int main()
{
  Summon_Tourist
  //freopen("input.txt" , "r" , stdin ) ;
  ll t = 1 ;
  //cin>>t ;
  while(t--)
  {
    ll n;
    cin>>n;
    string res = "";
    while(n>0)
    {
        n--;
        res += ( n%26 + 'a');
        n /=26 ;
    }
    for( ll i = res.size()-1 ; i>=0 ; i-- ) cout<<res[i];
  }
  return 0;

}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/
 
#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, n, a) for (int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(false); cin.tie(0) 
#define F first
#define S second
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)5e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

int n, a[MAXN];

int main() {
	#ifdef accepted
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif
	onlycin;
	cin >> n;
	rep(i, 1, n) cin >> a[i];
	sort(a+1, a+1+n);
	int x = a[n], y = a[1];
	rep(i, 1, n-1) {
		if(min(a[i], a[n]-a[i]) > min(y, a[n]-y)) y = a[i];
	}
	cout << x << ' '<< y << nxtl;
	
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
const int MAXn=100;

int n,M[MAXn][MAXn]={0},col[MAXn];//color:0=white,1=gray,2=brack
int d[MAXn],f[MAXn],t;

void dfs_visit(int u)
{
	int v;
	col[u]=1;
	d[u]=++t;
	for(v=0;v<n;v++)
	{
		if(M[u][v]==0)continue;
		if(col[v]==0)dfs_visit(v);
	}
	col[u]=2;
	f[u]=++t;
	return;
}

void dfs()
{
	int u;
	for(u=0;u<n;u++)col[u]=0;
	t=0;
	
	for(u=0;u<n;u++)if(col[u]==0)dfs_visit(u);
	
	for(u=0;u<n;u++)cout<<u+1<<" "<<d[u]<<" "<<f[u]<<endl;
	
	return;
}

int main() {
	cin>>n;
	int id,k,v;
	for(int i=0;i<n;i++)
	{
		cin>>id>>k;
		id--;
		for(int j=0;j<k;j++)
		{
			cin>>v;
			M[id][--v]=1;
		}
	}
	dfs();
	return 0;
}

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

#define ll long long int
#define ld long double
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f // 100'000'000'000'000
#define all(x) x.begin(),x.end()
#define show(x) cerr<<#x<<" : "<<x<<'\n';
#define yogeshk972() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();

using namespace std;
const int N= 1e5+10, mod=1e9+7;

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

	int n;
	cin>>n;
	vector<int> v(n+1);
	for(int i=1;i<n;i++){
		int x;
		cin>>x;
		v[x]++;
	}
	for(int i=1;i<=n;i++)cout<<v[i]<<"\n";
    return 0;
}



Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
const int INF  = 1<<30;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
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; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
#define COUT(x) cout<<x<<"\n";

void Main()
{
	ll A,B,C;
	ll result=0;
	string S="NO";
	cin>>A>>B>>C;
	REP(i, 101) {
		if(A*i%B==C)
			S="YES";
	}
	
	cout << S << "\n";
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 256