akhauriyash/Code-Regression huggingface dataset:
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

LL n, m;

vector<LL> PrimeFact(LL n) {
	vector<LL> res;
	while (n != 1) {
		if (n == 2 || n == 3) {
			res.emplace_back(n); n /= n;
			continue;
		}
		bool prime_flag = false;
		for (LL i = 2; i*i <= n; i++) {
			if (n%i == 0) {
				res.emplace_back(i); n /= i;
				prime_flag = true;
				break;
			}
		}
		if (!prime_flag) { res.emplace_back(n); n /= n; }
	}
	return res;
}

const LL MOD = 1000000007;
LL combi(LL N_, LL C_) {
	const int NUM_ = 400001;
	static LL fact[NUM_ + 1], factr[NUM_ + 1], inv[NUM_ + 1];
	if (fact[0] == 0) {
		inv[1] = fact[0] = factr[0] = 1;
		for (int i = 2; i <= NUM_; ++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
		for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i%MOD, factr[i] = factr[i - 1] * inv[i] % MOD;
	}
	if (C_<0 || C_>N_) return 0;
	return factr[C_] * fact[N_] % MOD*factr[N_ - C_] % MOD;
}

LL hcomb(int P_, int Q_) { return (P_ == 0 && Q_ == 0) ? 1 : combi(P_ + Q_ - 1, Q_); }

LL modpow(LL a, LL n = MOD - 2) {
	LL r = 1;
	while (n) r = r*((n % 2) ? a : 1) % MOD, a = a*a%MOD, n >>= 1;
	return r;
}

int main(){
    INIT;
    cin >> n >> m;
    vector<LL> v = PrimeFact(m);
    map<int, int> mp;
    REP(i, (int)v.size())mp[v[i]]++;
    LL ret = 1;
    for(auto it = mp.begin(); it != mp.end(); it++){
        ret *= hcomb(n, it->second);
        ret %= MOD;
    }
    cout << ret << endl;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S, T; cin >> S >> T;
  ll N = S.size();
  ll M = T.size();
  vector<vector<ll> > alp(26, vector<ll>());
  REPLL(i, N){
    alp[S[i]-'a'].push_back(i);
  }

  ll now = -1, cnt = 1, ans = 0;
  REPLL(i, M){
    if(alp[T[i]-'a'].size() == 0){
      cout << -1 << endl;
      return 0;
    }
    auto itr = lower_bound(alp[T[i]-'a'].begin(), alp[T[i]-'a'].end(), now+1);
    if(itr == alp[T[i]-'a'].end()){
      now = alp[T[i]-'a'][0];
      ans = cnt*N + now;
      cnt++;
    }else{
      ll tmp = *itr;
      if(now < 0) now = 0;
      ans += tmp-now;
      now = tmp;
    }
  }
  ans++;
  cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using ll = long long;
const int MOD = 1000000007;

int main() {
  int n;cin>>n;
  int an[1001];rep(i,1001)an[i]=0;
  rep(i,n) {
    int x=i+1;
    int j=2;
    while (x>1 and j<=x) {
      if (x%j==0) {
        an[j]++;
        x /= j;
      } else {
        j++;
      }
    }
  }
  ll ans=1;
  rep(i,1000) {
    ans = (ans * (an[i+1]+1)) % MOD;
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <stack>
#include <map>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

using ll = long long;

constexpr ll mod = 1000000007;

int N;
ll x[200001];
std::map<ll, bool> fl;
ll ans = 1;

int main()
{
  scanf( "%d", &N );
  rep( i, N )
    scanf( "%lld", x+i ), fl[x[i]] = false;
  rep( i, N )
    scanf( "%lld", x+N+i ), fl[x[N+i]] = true;

  std::sort( x, x+2*N );

  std::stack<int> s, t;
  rep( i, 2*N )
  {
    if( fl[x[i]] )
    {
      if( !s.empty() )
      {
        ans *= s.size();
        s.pop();
        ans %= mod;
      }
      else
        t.push(x[i]);
    }
    else
    {
      if( !t.empty() )
      {
        ans *= t.size();
        t.pop();
        ans %= mod;
      }
      else
        s.push(x[i]);
    }
  }

  printf( "%lld\n", ans );

  return 0;
}

Measured memory_bytes: 14720
#include<bits/stdc++.h>
using namespace std;
     
int n,a[100001],cnt,f;     
int main(){
 cin>>n;
 for(int i=0;i<n;i++)cin>>a[i];
 
 for(int i=0;i<n-1;i++)
  if(f==0){
   if(a[i]>a[i+1])f=1;
   else if(a[i]<a[i+1])f=2;
  }
  else if(f==1 && a[i]<a[i+1]){f=0;cnt++;}
  else if(f==2 && a[i]>a[i+1]){f=0;cnt++;}
       
 cout<<cnt+1<<endl;
 return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

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

    int count[2] = {0, 0};
    for(int i=0;i<X.size();i++){
        if(X[i] == 'S'){
            count[0]++;
        }else{
            count[1]++;
            if(count[0] >= 1){
                count[0]--;
                count[1]--;
            }
        }
    }
    cout << count[0] + count[1] << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int N, L;
  cin >> N  >> L;
  vector<string> S(N);
  for (int i = 0; i < N; i++){
    cin >> S.at(i);
  }
  
  sort(S.begin(), S.end());
  string s;
  for (int i = 0; i < N; i++){
    s += S.at(i);
  }
  cout << s << endl;
}

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

int main(){
	int ans = 0;
	int maxrest = 0;
	for(int i = 0; i < 5; i++)
	{
		int a;
		cin >> a;
		ans += ((a-1)/10+1) * 10;
		maxrest = max(maxrest, (10 - a % 10) % 10);
	}
	cout << ans - maxrest << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define ALL(v) v.begin(), v.end()
string s[10000];
int main() {
	int N;
	cin >> N;
	int ans = 0;
	int a = 0, b = 0, both = 0;
	for (int i = 0; i < N; i++) {
		cin >> s[i];
		for (int j = 0; j + 1 < s[i].size(); j++) {
			if (s[i][j] == 'A' && s[i][j + 1] == 'B') {
				ans++;
			}
		}
		if (s[i].back() == 'A' && s[i][0] == 'B') both++;
		else if (s[i].back() == 'A') a++;
		else if (s[i][0] == 'B') b++;
	}
	if (both > 0) {
		ans += both - 1;
		if (a > 0) {
			ans++;
			a--;
		}
		if (b > 0) {
			ans++;
			b--;
		}
	}
	ans += min(a, b);
	cout << ans << endl;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int d = stdIn.nextInt();
        
        int r = (n / (2 * d + 1));
        
        if(n % (2 * d + 1) != 0){
            r++;
        }
        
        
        System.out.println(r);
    }
}


Measured memory_bytes: 23892
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt(); //1行目の入力
		for(int i = 1; x != 0; i++){
			System.out.println("Case "+i+": "+x);
			x = sc.nextInt();
		}
	}
}


Measured memory_bytes: 41088
n,*s=open(0)
d={i:int(j)for i,j in zip('笑ABC',n.split())}
r=[]
for(i,j,_),(k,l,_)in zip(s,s[1:]):
    if d[i]<1>d[j]:exit(print('No'))
    if d[i]<1:
        d[i]+=1
        d[j]-=1
        r+=i,
    elif d[j]<1:
        d[i]-=1
        d[j]+=1
        r+=j,
    else:
        t={i,j}&{k,l}
        if t:
            t,*_=t
            u,*_={i,j}-{t}
        else:t,u=i,j
        d[t]+=1
        d[u]-=1
        r+=t,
i,j,_=s[-1]
if d[i]<1>d[j]:exit(print('No'))
if d[i]<1:
    d[i]+=1
    d[j]-=1
    r+=i,
else:
    d[i]-=1
    d[j]+=1
    r+=j,
print('Yes',*r)

Measured memory_bytes: 18384
#include <bits/stdc++.h>
using namespace std;
#define N 200005
#define MOD 998244353
#define mid (l+r>>1) 
int n,b[N],ps[N],dp[N];struct node {int x,y;}a[N];
struct Seg {int v;}sg[N<<2];
int max(int x,int y) {return x>y?x:y;} 
bool cmp(node x,node y) {return x.x<y.x;}
void pu(int p) {sg[p].v=max(sg[p<<1].v,sg[p<<1|1].v);}
void upd(int p,int l,int r,int x,int v)
{
	if(l==r) {sg[p].v=v;return;}
	if(x<=mid) upd(p<<1,l,mid,x,v);else upd(p<<1|1,mid+1,r,x,v);pu(p);
}
int qMx(int p,int l,int r,int qL,int qR)
{
	if(qL>qR) return 0;if(l>=qL && r<=qR) return sg[p].v;int res=0;
	if(qL<=mid) res=qMx(p<<1,l,mid,qL,qR);if(qR>mid) res=max(res,qMx(p<<1|1,mid+1,r,qL,qR));
	return res;
}
int main()
{
	scanf("%d",&n);for(int i=1;i<=n;++i) scanf("%d %d",&a[i].x,&a[i].y);
	sort(a+1,a+n+1,cmp);for(int i=1;i<=n;++i) b[i]=a[i].x;
	for(int i=n,t;i>=1;--i)
	{
		t=lower_bound(b+i+1,b+n+1,b[i]+a[i].y)-b-1;ps[i]=qMx(1,1,n,i+1,t);
		if(!ps[i]) ps[i]=i;upd(1,1,n,i,ps[i]);
	}dp[n+1]=1;
	for(int i=n;i>=1;--i) dp[i]=(dp[i+1]+dp[ps[i]+1])%MOD;printf("%d\n",dp[1]);
	return 0;
}

Measured memory_bytes: 7296
//**KEEP IT SHORT AND SIMPLE**
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILES freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define REP(i,a,b) for (int i = a; i < b; i++)
#define NL '\n'
#define F first
#define S second
#define dot(a, b) (conj(a) * (b)).real()
#define cross(a, b) (conj(a)* (b)).imag()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef bool bl;
typedef vector < vector<long long> > vvl;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
typedef map <long long, long long> mll;
typedef map <long long, bool> mlb;
typedef priority_queue<long long, vector<long long>, greater<long long> > minPq;
typedef tuple<ll, ll, ll> line;
typedef complex<double> point;
const double pi = 2 * acos(0.0);
const int OO = 0x3f3f3f3f;
int main()
{
    IO
    ll n, x;
    cin >> n;
    string s;
    map < string, vector<pll> >mp;
    REP(i, 1, n + 1)
    {
        cin >> s >> x;
        mp[s].push_back({x, i});
    }
    for(auto it : mp)
    {
        sort(it.S.rbegin(), it.S.rend());
        for(auto f : it.S)
            cout << f.S << NL;
    }
    return 0;
}


Measured memory_bytes: 256
using System;

namespace B___Resistors_in_Parallel
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var Ai = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            double result = 0;
            foreach (int i in Ai) result += (double)(1 / (double)i);
            Console.WriteLine(1/result);
        }
    }
}


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

void solve() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> a(h+2, vector<char>(w+2));
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> a[i][j];
        }
    }
    int di[] = {1, 0, -1, 0};
    int dj[] = {0, 1, 0, -1};
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if(a[i][j] == '.') {
                continue;
            }
            int x = 0;
            for (int k = 0; k < 4; k++) {
                x += (a[i + di[k]][j + dj[k]] == '#');
            }
           if(!x) {
               cout << "No";
               return;
           }

        }
    }
    cout << "Yes";
}

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


Measured memory_bytes: 3648
while 1:
    n = int(input())
    if n == 0:
        break

    best = 10**9
    for _ in range(n):
        p, h, w = map(int, input().split())

        bmi = w / (h / 100)**2
        diff = abs(bmi - 22)

        if diff < best:
            ans = p
            best = diff
        elif diff == best:
            if ans > p:
                ans = p

    print(ans)



Measured memory_bytes: 5616
console.log((args=>{
  let [[N,H],...katana] = args.trim().split`\n`.map(r=>r.split` `.map(v=>v|0));
  const B = [];
  let maxa = 0, count = 0;
  for ( const [a,b] of katana ) {
    if ( maxa < a ) maxa = a;
    B.push(b);
  }
  for ( const d of B.filter(v=>v>maxa).sort((a,b)=>b-a) ) {
    count++;
    H -= d;
    if ( H <= 0 ) break;
  }
  return count + Math.ceil(Math.max(0,H)/maxa);
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 73940
import java.util.Scanner;

/**
 * Curtain
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int A = sc.nextInt();
            int B = sc.nextInt();

            int ans = Math.max(A - B * 2, 0);

            System.out.println(ans);
        }
    }

}


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

int main(){
    string s;
    char first='a';
    int k;
    vector<string> v;
    cin >> s >> k;
    
    for(char j='a';(int)j<(int)'z'+1;j++){
        for(int i=0;i<s.size();i++){
            if(s[i]==j){
                for(int a=0;a<5&&i+a<s.size();a++)
                    v.push_back(s.substr(i,a+1));
            }
        }
        sort(v.begin(),v.end());
        v.erase(unique(v.begin(),v.end()),v.end());
        if(v.size()>=k) break;
    }
    //   for(auto iter=v.begin();iter!=v.end();iter++) cout << *iter << endl;
    cout << v[k-1] << endl;

    return 0;
}

Measured memory_bytes: 1660
#include <stdio.h>          // printf(), scanf()
#include <stdlib.h>         // qsort()
#include <math.h>           // fabs()
#include <stdbool.h>

#define MAX_N 100
const double EPS = 1e-10;

typedef struct
{
	double x;
	double y;
} P;

P ps[MAX_N];
P qs[MAX_N * 2];
int n;
int m;

double
det(P *a, P *b)
{
	return a->x * b->y - a->y * b->x;
}

int
cmp_func(const void *l_, const void *r_)
{
	const P *l = (const P*) l_;
	const P *r = (const P*) r_;

	if (fabs(l->x - r->x) >= EPS)
	{
		if (l->x < r->x)
			return -1;

		if (l->x > r->x)
			return 1;
	}

	if (fabs(l->y - r->y) >= EPS)
	{
		if (l->y < r->y)
			return -1;

		if (l->y > r->y)
			return 1;
	}

	return 0;
}

void
convex_hull()
{
	P p, q;
	int i, j;

	qsort(ps, n, sizeof(P), cmp_func);
	m = 0;
	for (i = 0; i < n; ++i)
	{
		while (true)
		{
			if (m <= 1)
				break;

			p.x = qs[m - 1].x - qs[m - 2].x;
			p.y = qs[m - 1].y - qs[m - 2].y;
			q.x = ps[i].x - qs[m - 1].x;
			q.y = ps[i].y - qs[m - 1].y;
			if (det(&p, &q) > 0)
				break;

			m--;
		}

		qs[m++] = ps[i];
	}

	for (i = n - 2, j = m; i >= 0; --i)
	{
		while (true)
		{
			if (m <= j)
				break;

			p.x = qs[m - 1].x - qs[m - 2].x;
			p.y = qs[m - 1].y - qs[m - 2].y;
			q.x = ps[i].x - qs[m - 1].x;
			q.y = ps[i].y - qs[m - 1].y;
			if (det(&p, &q) > 0)
				break;

			m--;
		}

		qs[m++] = ps[i];
	}

	m--;
}

int
main(int argc, char **argv)
{
	while (true)
	{
		int i;
		scanf("%d", &n);
		if (n == 0)
			break;

		for (i = 0; i < n; ++i)
			scanf("%lf,%lf", &ps[i].x, &ps[i].y);

		convex_hull();
		printf("%d\n", n - m);
	}

	return 0;
}

Measured memory_bytes: 688
def c(x,y):
  i=0
  
  while i!=x:
    if (4*i)+(2*(x-i))==y:
      print("Yes")
      return
    
    elif (2*i)+(4*(x-i))==y:
      print("Yes")
      return
    i +=1
  
  print("No")
  return

n=list(map(int,input().split()))
c(n[0],n[1])


Measured memory_bytes: 9188
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;

const LL INF=1<<30;
const LL MOD=1000000007;

LL gcd(LL a,LL b){
    if(b==0)return a;

    return gcd(b,a%b);
}
        int n;
    int path[100100];
int solve(int kaisu,int where){
    if(where==2)return kaisu;
    if(kaisu>n)return -1;
    kaisu++;
    return solve(kaisu,path[where]);
}

int main(){
    cin>>n;
    for(int i=0;i<n;++i){
        int a;
        cin>>a;
        path[i+1]=a;      
    }
    cout<<solve(0,1)<<endl;
    
}

Measured memory_bytes: 640
module Main where

import Control.Applicative
import Numeric
import Data.Char

main :: IO ()
main = do
  { ln <- getLine
  ; putStrLn (map conv ln)
  }

conv :: Char -> Char
conv c | isLower c = toUpper c
       | otherwise = toLower c

--
getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""



Measured memory_bytes: 3912
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N, K;
	in >> N >> K;
	std::vector<LL>A(N);
	rep(i, N) in >> A[i];

	LL ans = 0;
	rep(i, N) ans += K ^ A[i];
	rep(i, 41)
	{
		if (K&(1LL << i))
		{
			LL res = 0;
			std::vector<LL>cnt(i);
			rep(j, N)
			{
				for (LL k = 40; k >= i + 1; --k)
				{
					if ((A[j] & (1LL << k)) ^ (K&(1LL << k))) res += (1LL << k);
				}
				if (A[j] & (1LL << i)) res += (1LL << i);
				for (LL k = i - 1; k >= 0; --k)
				{
					if (A[j] & (1LL << k)) ++cnt[k];
				}
			}
			for (LL k = i - 1; k >= 0; --k)
			{
				LL max_b = std::max(cnt[k], N - cnt[k]);
				res += max_b * (1LL << k);
			}
			ans = std::max(ans, res);
		}
	}

	out << ans << std::endl;
}


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


ll w[105],f[100005];
ll v[105];

signed main()
{
	ll N,W;
	while(cin>>N>>W){
		for(ll i=1;i<=N;i++)
		cin>>w[i]>>v[i];
		
		//01背包 
		memset(f,0,sizeof f);
		for(ll i=1;i<=N;i++){
			for(ll j=W;j>=w[i];j--)
			f[j]=max(f[j],f[j-w[i]]+v[i]);
		}	
		
		cout<<f[W]<<endl;
	}
}

Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  int l = a + b;
  int r = c + d;
  
  if (l > r)
  {
    cout << "Left";
  }
  else if (l == r)
  {
    cout << "Balanced";
  }
  else if (l < r)
  {
    cout << "Right";
  }
}

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

using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    vector<vector<int>> v(n);

    for (int i = 0; i < q; i++) {
        int a, t;
        cin >> a >> t;
        if (a == 0) {
            int x;
            cin >> x;
            v[t].push_back(x);
        } else if (a == 1) {
            for (int i = 0; i < v[t].size(); i++) {
                if (i > 0)cout << " ";
                cout << v[t][i];
            }
            cout << endl;
        } else {
            v[t] = vector<int>();
        }
    }

    return 0;
}


Measured memory_bytes: 5804
#include<iostream>
#include<cstring>
#include<sstream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int n, v[10000],sum=0;
	cin >> n;
	for (int i = 0;i < n;i++)
		cin >> v[i];

	for (int i = 0;i < n;i++) {
		for (int j = i + 1;j < n;j++) {
			sum = sum + v[i] * v[j];
		}
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		Scanner sc = new Scanner(System.in);

		//入力表示
		int A = sc.nextInt();
		int P = sc.nextInt();
		
		int applepiece =A*3;
		int total=applepiece+P; 
		int pai =total/2;
		 
		if(total>=1) {
		System.out.println(pai);
		}else {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 23124
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long M = sc.nextLong();
    if(N>M) { long tmp = M; M=N; N=tmp; }
    // may assume N<=M
    long result;
    if(M<=1) {
      result = 1;
    } else if(M<=2) {
      result = 0;
    } else {
      result = (N-2)*(M-2);
    }
    if(result<0) result = result * (-1);
    System.out.println(result);
  }
}


Measured memory_bytes: 23636
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
using namespace std;

int n, m;
map <int, int> Map;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		// Map[]?
		int x;
		scanf("%d", &x);
		Map[x] += 1;
	}
	scanf("%d",&m);
	while (m--) {
		int x;
		scanf("%d", &x);
		if (Map[x] == 0) {
			printf("NO\n");
			return 0;
		}
		Map[x] -= 1;
		// printf("YES\n");
	}
	printf("YES\n");
}

Measured memory_bytes: 9600
#include "bits/stdc++.h"

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, b, e) for (i64 i = (b); i <= (e); ++i)
#define repr(i, b, e) for (i64 i = (b); i >= (e); --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

#ifdef DEBUG
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// input
void input() {}
template <class Head, class... Tail>
void input(Head&& head, Tail&&... tail) {
  cin >> head;
  input(forward<Tail>(tail)...);
}

// outs
void outs() {}
template <class Head, class... Tail>
void outs(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  outs(forward<Tail>(tail)...);
}

template <class T>
void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void outs(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// outl
void outl() {}
template <class Head, class... Tail>
void outl(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  outl(forward<Tail>(tail)...);
}

template <class T>
void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// outn
void outn() {}
template <class Head, class... Tail>
void outn(Head&& head, Tail&&... tail) {
  cout << head;
  outn(forward<Tail>(tail)...);
}

template <class T>
void outn(vector<T> &vec) { for (auto &e : vec) cout << e; }

// dump
template <class T>
void dump_(const char *s, T&& x) {
  clog << '{';
  while(*s != '\0') clog << *(s++);
  clog << ": " << x << '}' << "\n";
}

template <class Head, class... Tail>
void dump_(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  dump_(s, forward<Tail>(tail)...);
}
// }}} End

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

  var(i64, a, b);
  outl((a - 1) * (b - 1));

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
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; }
const ll INF = 1LL << 60;
vector<P> an(100010), bn(100010);
int main(){
    int n;
    cin >> n;
    int m = n /2;
    vector<int> a(m),b(m);
    rep(i,m){
        cin >> a[i] >> b[i];
    }
    rep(i,m){
        an[a[i]].first++;
        bn[b[i]].first++;
    }
    rep(i,m){
        an[a[i]].second= a[i];
        bn[b[i]].second = b[i];
    }
    sort(an.begin(),an.end(),greater<P>());
    sort(bn.begin(),bn.end(),greater<P>());
    
    ll ans = 0;
    if(an[0].second!=bn[0].second){
        ans += n-an[0].first - bn[0].first;
    }else{
        ll mx = max(an[0].first+bn[1].first,an[1].first+bn[0].first);
        ans += n-mx;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  cout << (e - a <= k ? "Yay!\n" : ":(\n");
  return 0;
}


Measured memory_bytes: 3624
"""
author : halo2halo
date : 2, Feb, 2020
"""

import sys
import itertools

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a,b=(map(int, readline().split()))
print(b*(b-1)**(a-1))


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

int main() {
  long long n;
  cin>>n;
  set<long long> ds;
  for (long long i=1; i<=sqrt(n); i++) {
    if (n % i == 0) {
      ds.insert(i);
      if (i != n / i) {
        ds.insert(n / i);
      }
    }
  }
  ds.erase(1);
  ds.erase(2);
  long long ans = 0;
  for (long long d: ds) {
    long long m = d - 1;
    if (n / d <= m - 1) {
      ans += m;
    }
  }
  cout<<ans<<endl;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n, m;
  cin >> n >> m;
  
  ll ans =  abs((n-2)*(m-2)); 
  cout << ans << "\n";  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define mem0(x) memset(x,0,sizeof(x))
#define meminf(x) memset(x,0x3f,sizeof(x))
#define VI vector<int>
#define VL vector<ll>
using namespace  std;

const int N = 1e6+5;
int a[N];
VI prime;int vis[N];
void getprime(){
    rep(i,2,N-5){
        if(!vis[i]){
            prime.push_back(i);
        }
        for(int p:prime){
            int v = p*i;
            if(v>N-5) break;
            vis[v] = 1;
            if(i%p==0) break;
        }
    }
}
set<int> s[N];
int cntt[N];
int main(){
    ios::sync_with_stdio(0);
    getprime();
    int n;cin>>n; int gd;int fg = 1;
    rep(i,1,n){
        cin>>a[i];
        if(i>1&&gd != 1){
            gd = __gcd(gd,a[i]);
        }else if(i==1){
            gd = a[i];
        }
        if(fg&&a[i]!=1){
            
            if(!vis[a[i]]) {
                ++cntt[a[i]];
                if(cntt[a[i]]>1){
                    fg=0;
                }
            }
            else{
                //int lim = sqrt(a[i]+0.5);
                for(int p:prime){
                    //if(lim<p) break;
                    if(a[i]%p==0){
                        ++cntt[p];
                        if(cntt[p]>1){
                            fg=0;break;
                        }
                        if(!vis[a[i]/p]&&cntt[a[i]/p]>1){
                            fg=0;break;
                        }
                    }
                }
            }
            
        }
    }
    if(!fg){
        if(gd==1){
            cout<<"setwise coprime"<<'\n';
        }else{
            cout<<"not coprime"<<'\n';
        }
    }else{
        cout<<"pairwise coprime"<<'\n';
    }


    

    
}


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

// combination nCk（modなし）
// http://caprest.hatenablog.com/entry/2016/05/29/181102
ll comb(int n, int k){
	vector<vector<ll>> v(n+1,vector<ll>(n+1));
	for(int i = 0; i < v.size(); i++){
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for(int k = 1; k < v.size(); k++){
		for(int j = 1; j < k; j++){
			v[k][j] = v[k-1][j-1] + v[k-1][j];
		}
	}
	return v[n][k];
}

int main() {
	string s;
	int k;
	cin >> s >> k;
	int n = s.size();
	if (n < k) {
		cout << 0 << endl;
		return 0;
	}
	
	ll ans = 0;
	for (int i = k; i <= n-1; i++) {
		ll now =  9 * comb(i-1, k-1);
		rep(j, k-1) now *= 9;
		ans += now;
	}
	int f0 = s[0]-'0', f1, f2;
	int non_zero_index1 = -1;
	int non_zero_index2 = -1;
	rep(i, n) {
		if(i == 0) continue;
		if(s[i] != '0') {
			non_zero_index1 = i;
			f1 = s[i]-'0';
			break;
		}
	}
	if (non_zero_index1 > 0) for(int i = non_zero_index1 + 1; i < n; i++) {
		if(s[i] != '0') {
			non_zero_index2 = i;
			f2 = s[i]-'0';
			break;
		}
	}
	if (k == 1) {
		ans += f0;
	} else if (k == 2) {
		// １ケタ目 == s[0]
		ll now1 = 0;
		if (non_zero_index1 > 0) now1 += f1;	// 2つ目がnon_zero_index1
		if (non_zero_index1 > 0 && non_zero_index1 < n-1) now1 += (n - non_zero_index1 - 1) * 9;	// 2つ目がnon_zero_index1未満
		// １ケタ目 != s[0]
		ll now2 = f0 - 1;
		now2 *= (n - 1) * 9;
		ans += now1 + now2;
	} else if (k == 3) {
		ll now1 = 0, now2 = 0, now3 = 0, now4 = 0;
		// １ケタ目 == s[0]
		if (non_zero_index1 > 0 && non_zero_index1 < n-1) {	// 2つ目がnon_zero_index1
			ll now2_1 = 0; // ２ケタ目 == f1
			if (non_zero_index2 > 0) now1 = f2; // 3つ目がnon_zero_index2
			if (non_zero_index2 > 0 && non_zero_index2 < n-1) now2_1 = (n - non_zero_index2 - 1) * 9; // 3つ目がnon_zero_index2未満
			
			ll now2_2 = f1 - 1; // ２ケタ目 != f1
			now2_2 *= (n - non_zero_index1 - 1) * 9;
			
			now2 = now2_1 + now2_2;
		}	
		if (non_zero_index1 > 0 && non_zero_index1 < n-2) now3 = comb((n - non_zero_index1 - 1), 2) * 9 * 9;	// 2つ目がnon_zero_index1未満
		
		// １ケタ目 != s[0]
		now4 = f0 - 1;
		now4 *= comb((n - 1), 2) * 9 * 9;
		ans += now1 + now2 + now3 + now4;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s;
    cin >> s;
    // A で始まる
    if(s[0] != 'A'){ cout << "WA\n"; return 0; }
    
    // C はちょうど1個
    int c = 0;
    for(int i = 2; i < s.size()-1; i ++){
        if(s[i] == 'C') c ++;
    }
    if(c != 1){ cout << "WA\n"; return 0; }
    
    c = 0;
    for(int i = 0; i < s.size(); i ++){
        if(s[i] >= 'A' && s[i] <= 'Z') c ++;
    }
    if(c != 2){ cout << "WA\n"; return 0; }
    
    cout << "AC\n";
}


Measured memory_bytes: 256
def my_gcd(a, b)
  while b!=0 do
    c=a%b
    a=b
    b=c
  end
  return a
end

def my_soinsu_bunkai(n)
  arr=[]
  arr<<1
  i = 2

  while (i*i)<=n
    #puts "now n = #{n}, arr = #{arr}"
    if n%i==0
      arr<<i
      while n%i==0 do
        n/=i
      end
    else
      i+=1
    end
  end
  #puts i
  #puts n 
  if n!=1
    arr<<n
  end
  return arr
end

a,b = gets.chomp.split(" ").map{|i|i = i.to_i}

g = my_gcd(a,b)
#puts "my_gcd(#{a},#{b}) = #{g}"
array = my_soinsu_bunkai(g)
#pp array
puts array.length
=begin
(Math.sqrt(g).to_i).times{|i|
  n = i+1
  if 
}
=end

Measured memory_bytes: 1788
#include<stdio.h>
int main(void){
        int i;
        char A[10],B[10],C[10],d,e;
        scanf("%s %s %s",A,B,C);
        for(i=0;i<=10;i++){
            if(A[i]=='\0'){
              d=A[i-1];
              break;
            }
        }
        for(i=0;i<=10;i++){
            if(B[i]=='\0'){
              e=B[i-1];
              break;
            }
        }
        if(d==B[0]&&e==C[0]){
          printf("YES\n");
        }
        else{
          printf("NO\n");
        }
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        String res;
        if(X>29){
            res = "Yes";
        }else{
            res = "No";
        }
        System.out.println(res);
                
            
        
        
        
        
        
        }
    }

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

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A==B && B!=C)cout << "Yes" << endl;
    else if(A==C && B!=C)cout << "Yes" << endl;
    else if(B==C && A!=C)cout << "Yes" << endl;  
    else{cout << "No" << endl;}
}

Measured memory_bytes: 256
def factorization(n):#素因数分解
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(i)

    if temp!=1:
        arr.append(temp)

    if arr==[]:
        arr.append(n)

    return arr
  

a,b=map(int,input().split())
al=factorization(a)
bl=factorization(b)

com=set(al) & set(bl)
if a==1 and b==1:
  print(1)
else:
  print(len(com)+1)


Measured memory_bytes: 9336
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC172C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int M = int.Parse(input[1]);
            long K = long.Parse(input[2]);
            string[] Ainput = Console.ReadLine().Split(' ');
            string[] Binput = Console.ReadLine().Split(' ');
            long[] A = new long[N+1];
            long[] B = new long[M+1];
            A[0] = 0;
            B[0] = 0;
            for(int i = 1; i <= N; i++)
            {
                A[i] = long.Parse(Ainput[i-1]);
            }
            for (int i = 1; i <= M; i++)
            {
                B[i] = long.Parse(Binput[i-1]);
            }
            for(int i = 1; i < N+1; i++)
            {
                A[i] += A[i - 1];
            }
            for (int i = 1; i < M+1; i++)
            {
                B[i] += B[i - 1];
            }
            long time = K;
            int best = M;
            while (time < B[best]&best>0)
            {
                best -= 1;
            }
            int count = best;
            //Console.WriteLine(count);
            //Console.WriteLine(best);
            int k = 1;
            while (K >= A[k] & k < N)
            {
                time = K - A[k];
                while (time < B[best] & best>0)
                {
                    best -= 1;
                }
                if (count < k + best)
                {
                    count = k + best;
                }
                k += 1;
                //Console.WriteLine(k);
            }
            if (K >= A[N])
            {
                time = K - A[N];
                while (time < B[best] & best > 0)
                {
                    best -= 1;
                }
                if (count < N + best)
                {
                    count = N + best;
                }
            }
            Console.WriteLine(count);
        }
    }
}


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

using namespace std;

#define ll long long
#define ini(arr, val) memset(arr, (val), sizeof(arr))
#define loop(i,n)  for(ll i=0; i<n; i++)
#define loop1(i,n)  for(ll i=1; i<=n; i++)

#define all(a)      (a).begin(),(a).end()
#define dupli(a)     unique(all(a)),(a).end()
#define exist(s,e)  (s.find(e)!=s.end())
#define dbg(x)  cout << #x << " is " << x << endl;
#define pt(x) cout<<x<<"\n"
#define pts(x) cout<<x<<" "

#define mp make_pair
#define pb push_back
#define f first
#define s second


#define inf (int)1e9
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007


#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test   int t; cin>>t; while(t--)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef set<int> si;

typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pll> vpll;
typedef vector<vl> vvl;
typedef map<ll,ll> mll;
typedef set<ll> sl;


//////////////////////////////////////////////////////////////////////////////////////////
//                      main starts
//////////////////////////////////////////////////////////////////////////////////////////
int const lmt=1e5+5;



int main(){

 //    #ifndef ONLINE_JUDGE
 //    freopen("../input.txt", "r", stdin);
 //    freopen("../output.txt", "w", stdout);
	// #endif
 //    fast
    
    
    int x,y;
    cin>>x>>y;
    if(y%2!=0){ pt("No"); return 0;}
    int c=0;
    loop(i,x+1){
    	int b=x-i;
    	if((2*i+4*b)==y){
    		c=1; break;
    	}
    }
    if(c) pt("Yes");
    else pt("No");
	
    

    

}


/*

// 

*/

Measured memory_bytes: 3564
#include <stdio.h>
int main(void){
	int A,B;;
	scanf("%d",&A);
	scanf("%d",&B);
	int ans;
	if (A > B){
	ans = 2*A-1;}
	else if(A == B){
	ans = A + B;}
	else {
	ans = 2*B -1;}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
	
using namespace std;
	
typedef long long ll;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef pair<pair<int,int>,bool> piib;
	
const ll N=501;
const int MOD=1e9+7;

int n;
string s;
	
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	
	#ifndef ONLINE_JUDGE
		//freopen("input.txt", "r", stdin);
		//freopen("out.txt", "w", stdout);
	#endif // ONLINE_JUDGE
	
	cin >> n;
    int ac=0,wa=0,tle=0,re=0;
    for(int i = 0; i < n; i++)
    {
        cin >> s;
        if(s=="AC")
            ac++;
        else if(s=="WA")
            wa++;
        else if(s=="TLE")
            tle++;
        else
            re++;
        
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    

	
	return 0;
}

Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}
	Scanner cin;
	const int MOD = 1000000007;
	const int INF = int.MaxValue;
	const double EPS = 1e-7;
	const double PI = 3.1415926536;

	void prog()
	{
		cin = new Scanner();
		int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
		int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

		int N = cin.nextInt();
		int[] a = new int[N];
		double ave = 0;
		for (int i = 0; i < N; i++)
		{
			a[i] = cin.nextInt();
			ave += a[i];
		}
		ave /= N;
		int tar = (int)Math.Round(ave);
		long ans = 0;
		for (int i = 0; i < N; i++)
		{
			ans += (tar - a[i]) * (tar - a[i]);
		}
		Console.WriteLine(ans);
	}
}

class Scanner
{
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

	public string next()
	{
		if (i < s.Length) return s[i++];
		string st = Console.ReadLine();
		while (st == "") st = Console.ReadLine();
		s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
		i = 0;
		return next();
	}

	public int nextInt()
	{
		return int.Parse(next());
	}

	public long nextLong()
	{
		return long.Parse(next());
	}

	public double nextDouble()
	{
		return double.Parse(next());
	}
}

Measured memory_bytes: 2904
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,n)cin>>v[i];
    
    static double dp[21][220011];
    rep(i,21)rep(j,220011)dp[i][j] = INF;
    dp[0][1] = 0;
    
    for(int i=1;i<=n;i++){
        for(int j=1;j<=220010;j++){
            double diff = (double)abs(v[i-1]-j)/v[i-1];
            int sq = sqrt(j);
            for(int k=1;k<=sq;k++){
                if(j%k==0){
                    dp[i][j] = min( dp[i][j], max( dp[i-1][k],   diff ) );
                    dp[i][j] = min( dp[i][j], max( dp[i-1][j/k], diff ) );
                }
            }
        }
    }
    double ans = INF;
    rep(i,220011)ans = min(ans,dp[n][i]);
    printf("%.20lf\n",ans);
}

Measured memory_bytes: 39324
#include <iostream>
int n, r, b;
std::string s;
int main(){
  std::cin >> n >> s;
  for(int i = 0; i < n; i++){
    if(s[i] == 'R') r++;
    else b++;
  }
  if(r > b) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
}

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

int main(){
  string str;
  cin >> str;
  int result = 0;
  for (int i = 0; i < 3; i++){
    if (str[i] == '1'){
    result += 1;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 3548
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
using namespace std;

int main(){
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vi(x, N);
    vi(y, M);
    rep(i, N) cin >> x[i];
    rep(i, M) cin >> y[i];
    srt(x);
    srt(y);
    string ans = "War";
    rng(i, X+1, Y+1){
        if((x[N-1] < i) && (i <= y[0])){
            ans = "No War";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000)
N=int(input())
xy=[list(map(int,input().split()))+[i] for i in range(N)]
xy.sort()
path = []

def get_par(n):
    if par[n] is None:return n
    par[n] = get_par(par[n])
    return par[n]

def same(i,j):
    return get_par(i) == get_par(j)

def unite(i,j):
    j = get_par(j)
    par[j] = get_par(i)
    return

for k in range(N-1):
    x,y,i = xy[k]
    x2,y2,j = xy[k+1]
    path.append((abs(x-x2),i,j))
xy.sort(key=lambda x:x[1])
for k in range(N-1):
    x,y,i = xy[k]
    x2,y2,j = xy[k+1]
    path.append((abs(y-y2),i,j))
path.sort(key = lambda x:x[0],reverse=True)
par = [None]*N
cnt = 0
ans = 0
while cnt < N-1:
    c,i,j = path.pop()
    if same(i,j):continue
    unite(i,j)
    ans += c
    cnt += 1
print(ans)

Measured memory_bytes: 49164
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int w, h;
    char[][] map;
    int c;
    int[] dx = {0, 0, 1, -1};
    int[] dy = {1, -1, 0, 0};

    void run(){
	while(true){
	    w = sc.nextInt();
	    h = sc.nextInt();
	    if(h==0 && w==0) break;
	    c = 1;
	    map = new char[h][w];
	    int sx=0, sy=0;
	
	    for(int i=0; i<h; i++){
		String s = sc.next();
		map[i] = s.toCharArray();
		for(int k=0; k<w; k++)
		    if(map[i][k]=='@'){
			sx = k;
			sy = i;
		    }
	    }

	    solve(sx, sy);
	    System.out.println(c);
	}
    }

    void solve(int x, int y){
	int p, q;
	Stack<int[]> st = new Stack<int[]>();
	
	for(int i=0; i<4; i++){
	    p = x+dx[i];
	    q = y+dy[i];
	    if(p<0 || p>=w || q<0 || q>=h) continue;
	    if(map[q][p]=='.'){
		//System.out.println(q+" "+p);
		st.push(new int[]{q, p});
	    }
	}
	
	while(!st.isEmpty()){
	    int[] a = st.pop();
	    x = a[1];
	    y = a[0];
	    //System.out.println(map[y][x]+" "+y+" "+x);
	    if(map[y][x]!='.') continue;
	    for(int i=0; i<4; i++){
		p = x+dx[i];
		q = y+dy[i];
		if(p<0 || p>=w || q<0 || q>=h) continue;
		if(map[q][p]=='.'){
		    //System.out.println(q+" "+p);
		    st.push(new int[]{q, p});
		}
	    }
	    c++;
	    map[y][x] = '#';
	}
    }
}
		    

Measured memory_bytes: 29228
from collections import Counter


def main():
    r"""
    数列 a1,a2,...,anが以下の条件を満たすとき、 /\/\/\/ と呼ぶ

        各 i=1,2...,n-2 について、ai=ai+2
        数列に現れる数はちょうど 2種類偶数長の数列

    v1,v2,...,vnが与えられます
    要素をいくつか書き換えることでこの数列を /\/\/\/ にしたいです。
    書き換える要素の数は最小でいくつになるか求めてください。

    2 <= n <= 10^5, nは偶数
    1 <= vi <= 10^5, viは整数
    """
    n = int(input())
    *v, = map(int, input().split())

    ans = f(n, v)
    assert ans == simple(n, v)
    print(ans)


def simple(n, v):
    # most_commonを事前に使い短くする
    # 1種類しかないならば存在しない種類を0個で足して条件分岐を潰す
    c1 = Counter(v[::2]).most_common() + [(0, 0)]
    c2 = Counter(v[1::2]).most_common() + [(0, 0)]

    if c1[0][0] == c2[0][0]:
        n_no_change = max(c1[0][1] + c2[1][1],
                          c1[1][1] + c2[0][1])
        return n - n_no_change
    else:
        return n - c1[0][1] - c2[0][1]

def f(n, v):
    """
    3 1 3 2:
        3種類
        a1=a3, a2 != a4
    """
    ans = float("inf")
    v_idx_even = []
    v_idx_odd = []
    for i, x in enumerate(v):
        if i % 2 == 0:
            v_idx_even.append(x)
        else:
            v_idx_odd.append(x)

    ve = Counter(v_idx_even)
    vo = Counter(v_idx_odd)

    if len(ve) == 1 and len(vo) == 1:
        # 両方1種類
        ans = 0
        if ve.most_common()[0][0] == vo.most_common()[0][0]:
            ans = n // 2

    elif len(ve) == 1 or len(vo) == 1:
        # 片方1種類
        idx = 0
        if ve.most_common()[0][0] == vo.most_common()[0][0]:
            idx = 1
        if len(ve) == 1:
            ans = n // 2 - vo.most_common()[idx][1]
        else:
            ans = n // 2 - ve.most_common()[idx][1]

    else:
        # 両方2種類以上
        if ve.most_common()[0][0] != vo.most_common()[0][0]:
            ans = n - ve.most_common()[0][1] - vo.most_common()[0][1]
        else:
            ans = n - \
                max(ve.most_common()[0][1] + vo.most_common()[1][1],
                    ve.most_common()[1][1] + vo.most_common()[0][1])

    return ans


if __name__ == '__main__':
    main()


Measured memory_bytes: 20588
#include <stdio.h>
int main(void){
   
   int a,b,d,r;
   double f;
   
   scanf("%d %d",&a,&b);
   
   d=a/b;
   r=a%b;
   f=(double)a/b;
   
   printf("%d %d %.5lf\n",d,r,f);
   
   return 0;
}



Measured memory_bytes: 2104