akhauriyash/Code-Regression huggingface dataset:
/*
  AtCoder Beginner Contest 079
  C - Train Ticket

  方針
    演算子（op）は3つしかない。各演算子につき、プラス（+）もしくはマイナス
    （-）を選択すればよい。したがって、O(2^3)を全探索すればよい。
  
  実装
    方針の通りに実行する。
*/

#include<iostream>
#include<string>
using namespace std;

string str;
int ABCD[4];

int main() {
  cin >> str;

  for (int i = 0; i < 4; ++i) {
    ABCD[i] = (int)(str[i] - '0');
  }

  // 0: +, 1: -
  for (int i = 0; i <= 1; ++i) {
    for (int j = 0; j <= 1; ++j) {
      for (int k = 0; k <= 1; ++k) {
        int buf = ABCD[0];
        buf = i ? buf + ABCD[1] : buf - ABCD[1];
        buf = j ? buf + ABCD[2] : buf - ABCD[2];
        buf = k ? buf + ABCD[3] : buf - ABCD[3];
        if (buf == 7) {
          printf("%d", ABCD[0]);
          if (i) printf("+");
          else printf("-");
          printf("%d", ABCD[1]);
          if (j) printf("+");
          else printf("-");
          printf("%d", ABCD[2]);
          if (k) printf("+");
          else printf("-");
          printf("%d=7\n", ABCD[3]);
          return 0;
        }        
      }
    }
  }

  return 0;
}

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

using ll = long long;
using namespace std;

int main(void) {
    int n;
    cin >> n;
    vector<ll> a(n+1), b(n);

    ll original = 0;
    for( int i = 0; i < n+1 ; ++i) {
        cin >> a[i];
        original += a[i];
        // cout << "i"<<i << endl;
    }

    for( int j = 0;j < n; ++j) {
        cin >> b[j];
        // cout << "j"<<j << endl;
    }

    ll attacked = 0;
    ll next_attacked = 0;
    ll attacked_sum = 0;
    for(int city_i = n; city_i > 0; --city_i) {
        // fisrt attack
        attacked = a[city_i] - b[city_i-1];
        // cout << "a["<<city_i<<"] = " << a[city_i] << endl;
        // cout << "first_attack:" << city_i << " " << attacked << endl;
        // cout << "yusya power:" << b[city_i-1] << endl;
        if (attacked < 0) {
            a[city_i] = 0;
            // next attack
            next_attacked = a[city_i -1] + attacked;
            // cout << "a["<< city_i-1<< "] = " << a[city_i-1] << endl;
            // cout << "next_attack:" << city_i -1 << " " << next_attacked << endl;
            // cout << "yusya power:" << attacked << endl;

            if(next_attacked < 0) {
                a[city_i - 1] = 0;
            } else {
                a[city_i - 1] = next_attacked;
            }
            // cout << "attacked:" << attacked << endl;
        } else {
            a[city_i] = attacked;
            // cout << "all_attacked" << endl;
        }

        // a[city_i]+=attacked_sum;
        // cout << city_i << endl;
        attacked = 0;
        next_attacked = 0;
    }

    // attacked_sum += a[0];

    // // city
    // cout << "city current situation" << endl;
    ll after = 0;
    for(int i = 0; i < n+1; ++i) {
        // cout << a[i] << " ";
        after += a[i];
    }
    // cout << endl;

    // cout << original << endl;
    // cout << after << endl;

    cout << original - after << endl;
    

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstring>

using namespace std;

int main() {
	int mode[100];
	int a, v = 0;

	memset(mode, 0, sizeof(mode));
	while (cin >> a) {
		mode[a-1] += 1;
	}
	for (int i = 0; i < 100; i++)
		v = max(v, mode[i]);
	for (int i = 0; i < 100; i++)
		if (mode[i] == v)
			cout << i+1 << endl;
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int m=55555;
  vector<bool> p(m+1,1);
  for(int i=2;i<=m;i++){
    if(!p.at(i))
      continue;
    for(int j=2;i*j<=m;j++)
      p.at(i*j)=0;
  }
  for(int i=2;i<=m;i++)
    if(i%5!=1)
      p.at(i)=0;
  for(int i=2,c=0;i<=m&&c<n;i++){
    if(p.at(i)){
      c++;
      cout<<i<<(c<n?" ":"");
    }
  }
  cout<<endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define int long long
#define all(c) (c).begin(),(c).end()
#define endl '\n'
using namespace std;

//                                      mdsaqib
signed main(){
    fast;
    int t=1;
    //cin >> t;
    while(t--){
        int n,k;
        cin >> n >> k;
        vector <int> A(n,0);
        for(int i=0;i<n;i++){
            cin >> A[i];
        }
        sort(all(A));
        int sum=0;
        for(int i=0;i<k;i++){
            sum+=A[i];
        }
        cout << sum;
    }
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>
using namespace std;


int main(){
	vector<double> ans_x;
	vector<double> ans_y;
	double a, b, c, d, e, f;
	double tb, tc, te, tf;
	double x, y;
	int i, cnt=0;
	while(cin>>a>>b>>c>>d>>e>>f){
		tb=b*d;
		tc=c*d;
		te=e*a;
		tf=f*a;
		tb-=te;
		tc-=tf;
		y=tc/tb;
		x=(c-b*y)/a;
		ans_x.push_back(x);
		ans_y.push_back(y);
		cnt++;
	}
	for(i=0;i<cnt;i++){
	//	cout.precision(4);
	//	cout.setf(ios::showpoint);
		printf("%.3f %.3f\n",ans_x[i], ans_y[i]);
	}
	return 0;
}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, int b, int _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

// youtube editorial
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  rep(i, n) a[i] -= i + 1;
  sort(all(a));

  // b を真ん中 (n が偶数ならどっちでもいい) にする
  // 他の点に置くと, ちょっと動いたとき合計値がどうなるか考える
  ll sum = 0;
  rep(i, n) sum += abs(a[i] - a[n / 2]);
  cout << sum << endl;
}


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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define MOD 1000000007

//cout << (c)?"Yay!":":(" << endl;

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    long long int n, a, b;
    cin >> n >> a >> b;
    long long int hoge = n / (a + b);
    long long int amari = n % (a + b);
    if (amari > a)
        hoge = (hoge + 1) * a;
    else
        hoge = hoge * a + amari;
    cout << hoge << endl;
    return 0;
}


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

int main()
{
    long long N;
    cin >> N;
    using col = tuple<string, long long, long long>;
    vector<col> p(N);
    for (int i = 0; i < N; i++)
    {
        string a;
        int b;
        cin >> a >> b;
        auto g = make_tuple(a, b, i);
        p.at(i) = g;
    }

    sort(p.begin(), p.end());
    int i = 0;
    while (i < N)
    {
        if (i == N - 1)
        {
            break;
        }
        int init = i;
        string p1 = get<0>(p.at(i));
        string p2 = get<0>(p.at(i + 1));
        while (p1 == p2)
        {
            i++;
            if (i == N - 1)
            {
                break;
            }
            p1 = p2;
            p2 = get<0>(p.at(i + 1));
        }
        int num = i - init + 1;
        vector<pair<int, int>> li(num);
        for (int j = 0; j < num; j++)
        {
            int a, b;
            tie(ignore, a, b) = p.at(j + init);
            auto l = make_pair(a, b);
            li.at(j) = l;
        }
        reverse(li.begin(), li.end());
        for (int j = 0; j < num; j++)
        {
            int b, k;
            string a;
            tie(a, ignore, ignore) = p.at(j + init);
            tie(b, k) = li.at(j);
            auto g = make_tuple(a, b, k);
            p.at(j + init) = g;
        }
        i++;
    }
    for (int i = 0; i < N; i++)
    {
        cout << get<2>(p.at(i)) + 1 << endl;
    }
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>

#pragma warning( disable: 4996 )

using namespace std;

typedef long long ll;

#define INF 100000000
#define EPS 1e-9

#define MAX_N 100

int n;
vector<int> ans_list;

int main(){
	
	while (true){
	
		cin >> n;
		if (n == 0)
			break;

		vector<int> score;

		for (int i = 0; i < n; i++){
			int s;
			cin >> s;
			score.push_back(s);
		}
	
		sort(score.begin(), score.end());

		int ans = 0;

		for (int i = 1; i < score.size() - 1; i++){
			ans += score[i];
		}

		ans_list.push_back(ans / (score.size() - 2));
	
	}

	for (int i = 0; i < ans_list.size(); i++){
		cout << ans_list[i] << endl;
	}

	return 0;

}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> bingo(9);
  int N,p;
  for(int i=0;i<9;i++) {
    cin >> bingo.at(i);
  }
  cin >> N;
  for(int i=0;i<N;i++) {
	cin >> p;
    for(int j=0;j<9;j++) {
      if(p==bingo.at(j)) {
        bingo.at(j)=0;
        break;
      }
    }
  }
  if(bingo.at(0)==bingo.at(1)&&bingo.at(0)==bingo.at(2)) cout <<"Yes" << endl;
  else if(bingo.at(3)==bingo.at(4)&&bingo.at(3)==bingo.at(5)) cout <<"Yes" << endl;
  else if(bingo.at(6)==bingo.at(7)&&bingo.at(6)==bingo.at(8)) cout <<"Yes" << endl;
  else if(bingo.at(0)==bingo.at(3)&&bingo.at(0)==bingo.at(6)) cout <<"Yes" << endl;
  else if(bingo.at(1)==bingo.at(4)&&bingo.at(1)==bingo.at(7)) cout <<"Yes" << endl;
  else if(bingo.at(2)==bingo.at(5)&&bingo.at(2)==bingo.at(8)) cout <<"Yes" << endl;
  else if(bingo.at(0)==bingo.at(4)&&bingo.at(0)==bingo.at(8)) cout <<"Yes" << endl;
  else if(bingo.at(2)==bingo.at(4)&&bingo.at(2)==bingo.at(6)) cout <<"Yes" << endl;
  else cout << "No" << endl;
}

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

namespace arc060_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            for (int i = 0; i < x[0]; i++) a[i] -= x[1];
            long[,] dp = new long[x[0],10000]; dp[0,5000]++; dp[0,5000 + a[0]]++;
            for (int i = 1; i < x[0]; i++)
            {
                for (int j = 0; j < 10000; j++)
                {
                    dp[i,j] += dp[i - 1,j];
                    int n = j - a[i];
                    if (10000 > n && n >= 0) dp[i,j] += dp[i - 1,n];
                }
            }
            Console.WriteLine(dp[x[0] - 1,5000] - 1);
        }
    }
}

Measured memory_bytes: 16864
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
	os << p.first << " " << p.second;
	return os;
}

template <class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
	for (const auto &e : mp) os << "[" << e << "] ";
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	lint N, A, B;
	cin >> N >> A >> B;

	vector<lint> h(N);
	for (int i = 0; i < N; i++) cin >> h[i];
	sort(h.begin(), h.end());

	auto biSearch = [&](auto f) {
		lint ng = -1;
		lint ok = h.back();

		while (abs(ok - ng) > 1) {
			lint mid = (ok + ng) / 2;

			if (f(mid)) ok = mid;
			else ng = mid;
		}

		return ok;
	};

	auto judge = [&](int idx) {

		lint ex = 0;
		for (int i = 0; i < N; i++) {
			if (h[i] - B * idx > 0) ex += (h[i] - B * idx - 1) / (A - B) + 1;
			DMP(ex);
		}

		DMP(idx, ex);
		return ex <= idx;

	};

	cout << biSearch(judge) << "\n";

	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int n, m;
	while(scanf("%d %d", &n, &m))
	{
		bool ok=true, go=false;
		if(n==0 && m==0)
		{
			break;
		}
		for(int i=0;i<n;i++)
		{
			if(ok)
			{
				go=true;
				for(int j=0;j<m;j++)
				{
					if(go)
					{
						printf("#");
						go=false;
					}
					else
					{
						printf(".");
						go=true;
					}
				}
				printf("\n");
				ok=false;
			}
			else
			{
				go=true;
				for(int j=0;j<m;j++)
				{
					if(go)
					{
						printf(".");
						go=false;
					}
					else
					{
						printf("#");
						go=true;
					}
				}
				printf("\n");
				ok=true;
			}
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2624
#include<stdio.h>

int main(void)
{
    int a, b, c, d;
    
    scanf("%d %d %d", &a, &b, &c);
    
    if(a > b){
        d = a;
        a = b;
        b = d;
    }
    if(b > c){
        d = c;
        c = b;
        b = d;
    }
    if(a > b){
        d = a;
        a = b;
        b = d;
    }
    
    printf("%d %d %d", a, b, c);
    
    putchar('\n');
    
    return 0;
}


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

using namespace std;


typedef long long ll;

#define F0R(i, a) for (int i=0; i<(a); i++)

#define sz(x) (int)(x).size()

void Print(int *arr, int n)
{
	for(int i=0; i<n; i++) cout<<arr[i]<<" "; 
	cout<<endl; 
}


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

    string S; cin >> S;

    int count[2];
    count[0] = 0;
    count[1] = 0;
    int lastPair = -1;
    char cur = 'R';
    int N = sz(S);
    int ans[N]; F0R(i, N) ans[i] = 0;
    F0R(i, N) {
    	//cout<<"\n*****S["<<i<<"]="<<S[i]<<endl; 
        if (S[i] == cur) {
        	///nothing 
        	
            ///count[i%2]++;
        } 
        else {
            if (S[i] == 'L') {
                lastPair = i-1;
                
            }
            ans[lastPair] += count[lastPair%2];
               ans[lastPair+1] += count[(lastPair+1)%2];
            count[0] = 0;
            count[1] = 0;
            
            cur = S[i];
            //cout<<"#changed cur="<<cur<<endl; 
        }
        count[i%2]++;
        
        

    }

    ans[lastPair] += count[lastPair%2];
    ans[lastPair+1] += count[(lastPair+1)%2];

    F0R(i, N) {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}




Measured memory_bytes: 1104
n = int(input())
h = tuple(map(int, input().split()))

dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

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


def ceil(a, b):
    return (a + b - 1) // b


T, A = 1, 1
for _ in range(N):
    Tt, At = map(int, input().split())
    x = max(ceil(T , Tt), ceil(A , At))
    T, A = Tt * x, At * x
print(T + A)


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

int main(){
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  
  
  for(int i = 0; i < k; i++){
    if(a >= b) b*= 2;
    else c *= 2;
  }
  
  if(a < b && b < c) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3584
x=range(int(input())-1,-1,-1)
P=[]
for _ in x:P+=[[int(i) for i in input().split()]]
P+=[P[0]]
for j in x:_+=P[j+1][1]*P[j][0]-P[j][1]*P[j+1][0]
print(_*0.5)

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

int main()
{
    string a;
    getline(cin,a);
    if(a[0]=='S') printf("Cloudy");
    else if(a[0]=='C') printf("Rainy");
    else if(a[0]=='R') printf("Sunny");
    return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return (((res * res)%MOD) * a)%MOD; 
    else
        return (res * res)%MOD;
}

int main(){
    //freopen("a.in", "r", stdin);
    int n, k; cin >> n >> k;
    long long num[k+1];
    fill(num, num+k+1, 0);
    long long ans = 0;
    for(int i = 1; i<=k; i++){
        int tobe = i-num[i];
        ans += tobe*binpow(k/i, n);
        ans %= MOD;
        for(int j = i; j<=k; j+=i) num[j] += tobe;
    }
    cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    int a, b,sum=0;
    cin >> a >> b;
    rep(i, 2) {
        if (a > b) {
            sum += a;
            a--;
        }
        else {
            sum += b;
            b--;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
""" abc062_a:A - Grouping """
L = input().rstrip().split(' ')

if L[0] == "2" or L[1] == "2":
    print("No")
else:
    for i in range(2):
        num = int(L[i])
        if num > 7:
            num = num - 7
        L[i] = num % 2

    if L[0] == L[1]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3060
S=list(input())

abc=set([chr(ord('A')+i) for i in range(26)])

if S[0]=='A':
    cnt=0
    ind=0
    for i in range(2,len(S)-1):
        if S[i]=='C':
            cnt+=1
            ind=i
    if cnt==1:
        del S[ind]
        del S[0]
        for s in S:
            if s in abc:
                print('WA')
                exit()
        print('AC')
        exit()
print('WA')



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

int main(){
   int H,W;
   cin >> H >> W;
   
   vector<string> S(H);
   vector<vector <char>> s(H,vector <char>(W));
   for(int i=0; i<H; i++){
       cin >> S.at(i);
       for(int j=0; j<W; j++){
           s.at(i).at(j) = S.at(i).at(j);
       }
   }

      vector<vector<char>> ans(H,vector<char>(W));

   for(int i=0; i<H; i++){
       for(int j=0; j<W; j++){
           char countij='0';
           if(s.at(i).at(j) == '#'){
               ans.at(i).at(j) = '#';
           }
           else{
               for(int k=i-1; k<=i+1; k++){
                   for(int l=j-1; l<=j+1; l++){
                       if((0 <= k && k <= H-1) && (0 <= l && l <= W-1)){
                           if(s.at(k).at(l) == '#'){
                               countij++;
                           }
                       }
                       ans.at(i).at(j) = countij;
                   }
               }
           }
       }
   }

   
   for(int i=0; i<H; i++){
       for(int j=0; j<W; j++){
           if(j == W-1){
               cout << ans.at(i).at(j) << endl;
           }
           else{
               cout << ans.at(i).at(j);
           }
       }
   }
}

Measured memory_bytes: 256
# matrixの基本操作

def same_el(array_)
  if array_.kind_of?(Array)
    output = []
    for i in  0..(array_.count-1)
      output.push(array_[i])
    end
  end
  return output
end

# ---------------------------------------------

def replace(n)

  sgn=[]
  remain=[]
  output=[] #n!個の要素を持つ配列を返す
  for i in 0..n
    sgn << i
    remain << i
  end
  output << []
  for i in 0..n
    output[0] << i
  end

  while true
    remain_act = same_el(remain)
    remain_act.delete(0)
    for i in 1..n-1
      judge_order = true
      for j in i+1..n-1
        sgn[j]<sgn[j+1] && judge_order = false
      end
      judge_order && break
      remain_act.delete(sgn[i])
    end
    singular = i
    remain_act.sort!
    for i in 0..n-(singular-2)
      if sgn[singular] == remain_act[i]
        sgn[singular] = remain_act[i+1]
        break
      end
    end
    remain_act.delete(sgn[singular])
    for i in singular+1..n
      sgn[i] = remain_act[i-(singular+1)]
    end
    inp =same_el(sgn)
    output << inp
    lastmat=true
    for i in 1..n
      sgn[i] != n+1-i && lastmat=false
    end
    lastmat && break
  end

  for i in 0..output.count-1
    output[i].delete(0)
  end
  output
end

# ---------------------------------------------

def signal(replaces)
  output = Array.new
  index = Array.new

  replace.size.times do |i|
    for j in 0..replaces.size-1
      index[j] = j+1
    end
    i_op = i.clone
    while true
      j = 0
      nimotu = index[0]
      sgn_part = -1
      while true
        if i_op[j] == nimotu

        else
        end
      end

    end
    output << sgn
  end
end

N=gets.to_i
ar=replace(N)
ps=gets.split.map(&:to_i)
qs=gets.split.map(&:to_i)
p (ar.index(ps)-ar.index(qs)).abs

Measured memory_bytes: 13308
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define debug(x) cout << #x << ":\t" << x << endl
#define _ << " " <<

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const ll N = 1e2 + 3;
const ll M = 1e5 + 3;
const ll mod = 1e9 + 7;

ll n, k, a[N], sum;
ll dp[N][M];

int main() {
//	mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
//	freopen("in", "r", stdin)
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	cin >> n >> k;
	for (ll i = 1; i <= n; ++i) {
		cin >> a[i];
		sum += a[i];
	}
	
	if (sum < k) {
		return cout << 0 << "\n", 0;
	}
	
	for (ll i = 0; i <= n; ++i) dp[i][0] = 1;
	
	for (ll i = 1; i <= n; ++i) {
		for (ll j = 1; j <= k; ++j) {
			auto normalize = [&](ll& x, ll y, ll mod) {
				x -= y;
				if (x < 0) x += mod;
			};
			
			dp[i][j] += (dp[i][j-1] + dp[i-1][j]) % mod;
			if (j > a[i]) {
				ll x = j - a[i] - 1;
				normalize(dp[i][j], dp[i-1][x], mod);
			}
		}
	}
	cout << dp[n][k] << "\n";
	
	return 0;
}


Measured memory_bytes: 79360
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func main() {
	sc.Split(bufio.ScanWords)
	var n int
	var M [101][101]int

	n = nextInt()

	P := make([]int, n*2)

	for i := 1; i <= n; i++ {
		P[i-1] = nextInt()
		P[i] = nextInt()
	}
	for l := 2; l <= n; l++ {
		for i := 1; i <= n-l+1; i++ {
			j := i + l - 1
			M[i][j] = 1000000
			for k := i; k <= j-1; k++ {
				M[i][j] = int(math.Min(float64(M[i][j]), float64(M[i][k]+M[k+1][j]+P[i-1]*P[k]*P[j])))
			}
		}
	}
	fmt.Println(M[1][n])
}



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

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



using namespace std;


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

    vector<int> sum(n,0);
    bool prev_a = s[0] == 'A';
    for(int i=1; i < n; i++) {
        if(prev_a && s[i] == 'C') {
            sum[i] += 1;
            prev_a = false;
        }
        if(s[i] == 'A') {
            prev_a = true;
        } else {
            prev_a = false;
        }
        sum[i] += sum[i-1];
    }

    int l,r;
    rep(i, q) {
        cin >> l >> r;
        cout << sum[r-1] - sum[l-1] << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <functional>
#include <cmath>
#include <array>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI;
typedef pair<int,int> pii;
const int md = (int)1e9+7;
const int MX = 200120;
ll  fct[MX];

ll bin_pow(ll x, ll n, ll mod){
	ll res = 1LL;
	for(; n > 0; n >>=1, x = x*x %mod) if(n & 1) res = res * x %mod;
	return res;
}

void init(int cmx){

	fct[0]=fct[1]=1;
	rep2(i,2,cmx+10) fct[i] = fct[i-1] * i % md;
}

ll cinv(ll s){
	return bin_pow(fct[s], md-2, md);
}

ll nCk_mod(ll n, ll k, ll mod=md) {
	ll ret =fct[n] * cinv(k) % mod * cinv(n-k) % mod;
	return ret;
}

int main()
{
	int h,w,a,b;
	cin >>h >>w >>a >>b;
	
	init(h+w+5);
	ll ans =0;
	rep(i, h-a){
		(ans += nCk_mod(i+b-1,b-1) * nCk_mod(w-b-1+h-i-1,h-i-1)) %=md;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
import fractions
N,X=map(int,input().split())
X_list=list( map(int,input().split()) )

l = abs(X-X_list[0])
for i in range(len(X_list)-1):
  l = fractions.gcd(l,abs(X_list[i]-X_list[i+1]))
print(l)

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

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

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

struct UnionFindTree {
    int par[MAX_N];
    int rank[MAX_N];
    int siz[MAX_N];
    int minc[MAX_N];

    void init(int n) {
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) rank[x]++;
        par[y] = x;
        minc[x] = min(minc[x], minc[y]);
    }
    bool is_same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        x = find(x);
        return siz[x];
    }
};

int main() {
    int n, m;
    cin >> n;
    UnionFindTree g;
    g.init(n);
    map<string,int> mp;
    REP(i,n){
        string s;
        int c;
        cin >> s >> c;
        mp[s] = i;
        g.minc[i] = c;
    }
    cin >> m;
    REP(i,m){
        string s, t;
        cin >> s >> t;
        g.unite(mp[s],mp[t]);
    }
    int ans = 0;
    REP(i,n){
        int k = g.find(i);
        ans += g.minc[k];
    }
    cout << ans << endl;
    return 0;
}



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

int64_t MOD = 1000000007;
double PI = 3.141592653589793;

int main()
{
    int N;
    cin >> N;
    map<int, int> list;
    for (int x = 1; x <= 100; x++)
        for (int y = 1; y <= 100; y++)
            for (int z = 1; z <= 100; z++)
                if (x * x + y * y + z * z + x * y + y * z + z * x <= N)
                    list[x * x + y * y + z * z + x * y + y * z + z * x]++;
    for (int i = 1; i <= N; i++)
        cout << list[i] << endl;
}

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

using namespace std;

#define print(s) cout << (s) << endl;
#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n) 
#define all(a) (a).begin(), (a).end()
#define inf 10000000
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c; cin>> a>> b>> c;
    if ((b-a)==(c-b)){
        cout<<"YES"<<endl;
    } else{
        cout<<"NO"<<endl;
    }
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 100000

int parent(int);
int left(int);
int right(int);

int main(){
  int H,i,A[MAX+1];

  scanf("%d",&H);
  for(i=1;i<=H;i++)scanf("%d",&A[i]);

  for(i=1;i<=H;i++){
    printf("node %d: ",i);
    printf("key = %d, ",A[i]);
    if(parent(i)>=1)printf("parent key = %d, ",A[parent(i)]);
    if(left(i)<=H)printf("left key = %d, ",A[left(i)]);
    if(right(i)<=H)printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
  return 0;
}
int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}


Measured memory_bytes: 2112
//Dragon_warrior7(IITK)
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define ull unsigned ll
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) 
{
	cout << *it << " = " << a;
	nl;
	err(++it, args...);
}
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
void solveforthiscase(const int & test)
{//deb(test);
cin>>n;
ll ans[300000+100][5];
for(int i=0;i<=300000;i++)
{
    for(int j=0;j<3;j++)
    ans[i][j]=0;
}
//0 means r,1 means s,2 means p;
cin>>k;
ll sum=0;
ll r,s,p;
cin>>r>>s>>p;
string str;
cin>>str;
for(int i=n-1;i>=0;i--)
{
  if(str[i]=='r')
  {
     ans[i][0]=max(ans[i+k][1],ans[i+k][2]);
     ans[i][1]=max(ans[i+k][0],ans[i+k][2]);
     ans[i][2]=max(ans[i+k][1],ans[i+k][0])+p;
  }
  if(str[i]=='p')
  {
     ans[i][0]=max(ans[i+k][1],ans[i+k][2]);
     ans[i][1]=max(ans[i+k][0],ans[i+k][2])+s;
     ans[i][2]=max(ans[i+k][1],ans[i+k][0]);
  }
  if(str[i]=='s')
  {
     ans[i][0]=max(ans[i+k][1],ans[i+k][2])+r;
     ans[i][1]=max(ans[i+k][0],ans[i+k][2]);
     ans[i][2]=max(ans[i+k][1],ans[i+k][0]);
  }
}
for(int i=0;i<k;i++)
{
  sum+=max(max(ans[i][0],ans[i][1]),ans[i][2]);  
}
cout<<sum;
return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

Measured memory_bytes: 12288
#include <string>
#include <cstdio>
#include <unordered_map>
#include <deque>
#include <algorithm>
using namespace std;
typedef int key;

int main(){
	int N=3;
	unordered_map<key,deque<pair<key,long long>>>m;
	for(int i=0;i<N*N;i++){
		int k;
		scanf("%d",&k);
		m[i/N+N].emplace_back(i%N,k);
		m[i%N].emplace_back(i/N+N,-k);
	}
	for(;!m.empty();){
		auto s=m.begin()->first;
		deque<pair<key,long long>>st={{s,0}};
		unordered_map<key,long long>memo={{s,0}};
		for(;!st.empty();){
			auto p=*st.rbegin();st.pop_back();
			auto cur=p.first;long long d=p.second;
			for(auto &e:m[cur]){
				if(memo.find(e.first)==memo.end()){
					st.emplace_back(e.first,d+e.second);
					memo[e.first]=d+e.second;
				}else if(memo[e.first]!=d+e.second){
					puts("No");
					return 0;
				}
			}
		}
		for(auto &e:memo)m.erase(m.find(e.first));
	}
	puts("Yes");
}

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

// 節点の構造体を定義
struct Node {
  int key;
  struct Node *right, *left, *parent;
};

// rootとNILの構造体を初期化
struct Node *root;
struct Node *NIL;

void insert(int k) {
  //
  struct Node *y =  NIL;
  struct Node *x = root;
  struct Node *z;

  // insertする節点を初期化
  z = (struct Node *)malloc(sizeof(struct Node));

  // insertする節点のフィールドを初期化
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if (y == NIL) {
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void preParse(struct Node *u) {
  if (u == NIL) return;
  preParse(u->left);
  printf(" %d", u->key);
  preParse(u->right);
}

void inParse(struct Node *u) {
  if (u == NIL) return;
  printf(" %d", u->key);
  inParse(u->left);
  inParse(u->right);
}

int main() {

  int n, x;
  char com[10];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s%d", com, &x);
    if (com[0] == 'i') {
      insert(x);
    } else {
      preParse(root);
      printf("\n");
      inParse(root);
      printf("\n");
    }
  }
  return 0;
}



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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int64 fact[112345] = {};

int main(void){
	int32 N;
	vector<int64> a, b, c;
	cin >> N;
	a.resize(N);
	b.resize(N);
	REP(i, N) cin >> a[i];
	REP(i, N) cin >> b[i];
	REP(i, N){
		c.push_back(a[i]); c.push_back(b[i]);
	}
	sort(all(a)); sort(all(b));
	sort(all(c));
	c.erase(unique(all(c)), c.end());
	vector<int32> luz(2*N+1, 0);

	fact[0] = 1;
	REP(i, 112344) fact[i+1] = fact[i]*(i+1)%mod;

	REP(i, N){
		int32 l = min(a[i], b[i]), r = max(a[i], b[i]);
		l = lower_bound(all(c), l)-c.begin(); r = lower_bound(all(c), r)-c.begin();
		luz[l]++; luz[r+1]--;
	}
	REP(i, luz.size()-1)
		luz[i+1] += luz[i];

	int64 res = 1;
	REP(i, N){
		res *= luz[lower_bound(all(c), a[i])-c.begin()];
		res %= mod;
	}
	cout << res << endl;
}

Measured memory_bytes: 6000
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  if (s == "abc")
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
using System;

namespace ITP1_3_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var a = int.Parse(input[0]);
            var b = int.Parse(input[1]);
            var c = int.Parse(input[2]);
            var count = 0;
            for(int i = a; i <= b; i++)
            {
                if (c % i == 0)
                    count++;
            }
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 9176
import bisect


def resolve():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    ans = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            k = bisect.bisect_left(l, l[i] + l[j])
            ans += max(k - j - 1, 0)
    print(ans)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3188
using System;

namespace _0033
{
    class Program
    {
        static void Main(string[] args)
        {
            var dataNumber = int.Parse(Console.ReadLine());
            for (int i = 0; i < dataNumber ;i++ )
            {
                var input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    break;
                }

                var inputsAString = input.Split(' ');
                var BTop = 0;
                var CTop = 0;
                var answer = "YES";

                foreach(var inputA in inputsAString)
                {
                    if(BTop < int.Parse(inputA))
                    {
                        BTop = int.Parse(inputA);
                    }else if(CTop < int.Parse(inputA))
                    {
                        CTop = int.Parse(inputA);
                    }
                    else
                    {
                        answer = "NO";
                        break;
                    }
                }
                Console.WriteLine(answer);
            }
        }
    }
}

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

using namespace std;

// typedef
typedef long long ll;

// container util
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

// repetition
#define FOR(i,m,n) for(ll i = ((ll) m); i < ((ll) n); ++i)
#define REP(i,n) FOR(i,0,n)

int main() {
    int n, m;
    cin >> n >> m;
    int* c = new int[m];
    REP(i,m) cin >> c[i];
    int* dp = new int[n+1];
    REP(i, n+1) dp[i] = i;
    REP(i, m) {
        if(c[i] == 1) continue;
        FOR(j, c[i], n+1) {
            dp[j] = min(dp[j], dp[j - c[i]] + 1);
        }
    }
    cout << dp[n] << endl;
    return 0;
}

/*
dp[i][j] = i番目までのコインを使ってj円払うときのコインの最小枚数
dp[i][j] = min_{0..}{ dp[i-1][j - nc] + n }
         = min{ dp[i-1][j], min_{1..}{ dp[i-1][j - nc] + n } }
         = min{ dp[i-1][j], min_{0..}{ dp[i-1][j - c - nc] + n } + 1 }
         = min { dp[i-1][j], dp[i][j-c] + 1 }
*/


Measured memory_bytes: 3276
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLD = vector<PLD>;

const int INF = numeric_limits<int>::max();

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

    int n; cin >> n;
    vector<int> v(n,0); REP(i,n) cin >> v[i];

    int sum = 0;
    REP(i,n)
    {
        sum += v[i];
    }
    int ave = sum/n;
    int ave1 = ave + 1;
    int ave2 = ave - 1;

    int ans = 0;
    int ans1 = 0;
    int ans2 = 0;
    REP(i,n)
    {
        ans += (ave-v[i]) * (ave-v[i]);
        ans1 += (ave1-v[i]) * (ave1-v[i]);
        ans2 += (ave2-v[i]) * (ave2-v[i]);
    }

    cout << min(ans2, min(ans, ans1)) << endl;

    return 0;
}


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

class Program
{
    static void Main(string[] args) {
#if DEBUG
        //MyDebugger.MakeTestCase("../TextFile2.txt");
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = long.Parse(input.ReadLine());

        //n-1+n-2+...+1+0

        n = n - 1;
        if(n % 2 == 0) {
            return (n + 1) * (n / 2);
        } else {
            long n2 = n / 2;
            return (n + 1) * n2 + (n2+1);
        }
    }
}

Measured memory_bytes: 11092
/* 	* In the name of GOD 
 	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

int32_t main(){
	ld a, b;
	cin >> a >> b;
	cout << ll(a * b);
}


Measured memory_bytes: 3732
#include<stdio.h>
long long gbs(long long a,long long b){
	long long i,m,n,temp;
	m=a;
	n=b;
	if(m<n){
		temp=m;
		m=n;
		n=temp;
	}
	if(a<b){
		temp=a;
		a=b;
		b=temp;
	}
	for(;n!=0;){
		temp=m%n;
		m=n;
		n=temp;
	}
	return a/m*b;
} 
main(){
	long long n,a[100],i,m;
	while(scanf("%lld",&n)!=EOF){
		m=1;
		for(i=0;i<=n-1;i++){
			scanf("%lld",&a[i]);
			m=gbs(m,a[i]);
		}
		printf("%lld\n",m);
	}
}

Measured memory_bytes: 128
prime = [0,0] + [1]*(10**5-1) #0,1は素数でない
for x in range(2, 5 * 10**2 + 1):
    if prime[x]:
        for i in range(2, 10**5 // x + 1):
            prime[x*i] = 0

islike2017 = [0]*(10**5+1)
cnt = 0
for z in range(2, 10**5 + 1):
    if prime[z] and prime[(z+1)//2]:
        cnt += 1
    islike2017[z] = cnt

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

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

using namespace std;

//サイコロクラス
class Dice
{
public:
	int face[6];	//各面の値を保持
	
public:

	Dice(int val[])
	{
		face[0] = val[0];
		face[1] = val[1];
		face[2] = val[2];
		face[3] = val[3];
		face[4] = val[4];
		face[5] = val[5];
	}

	
	void ProcRoll(string s)
	{
		for (int i = 0; i < (int)s.size(); ++i)
		{
			switch (s[i])
			{
			case 'E':
				RollE();
				break;

			case 'W':
				RollW();
				break;

			case 'N':
				RollN();
				break;

			case 'S':
				RollS();
				break;


			}
		}
	}


private:

	//E方向に転がした時の処理
	void RollE()
	{
		//値の入れ替えは図を参照
		int tmp = face[0];
		face[0] = face[3];
		face[3] = face[5];
		face[5] = face[2];
		face[2] = tmp;
	}

	//W方向に転がした時の処理
	void RollW()
	{
		//値の入れ替えは図を参照
		int tmp = face[0];
		face[0] = face[2];
		face[2] = face[5];
		face[5] = face[3];
		face[3] = tmp;
	}

	//N方向に転がした時の処理
	void RollN()
	{
		//値の入れ替えは図を参照
		int tmp = face[0];
		face[0] = face[1];
		face[1] = face[5];
		face[5] = face[4];
		face[4] = tmp;
	}

	//S方向に転がした時の処理
	void RollS()
	{
		//値の入れ替えは図を参照
		int tmp = face[0];
		face[0] = face[4];
		face[4] = face[5];
		face[5] = face[1];
		face[1] = tmp;
	}


};


int main()
{
	//
	int input[6];

	//
	string str = "";

	//サイコロの面の値を取得
	cin >> input[0] >> input[1] >> input[2] >> input[3] >> input[4] >> input[5];

	//
	cin >> str;

	//サイコロクラスの宣言
	Dice dice(input);

	//サイコロを指定の方向に転がす
	dice.ProcRoll(str);

	//
	cout << dice.face[0] << endl;


}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
#include <atcoder/all>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;
using namespace atcoder;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

ll op(ll a,ll b) {
    return max(a, b);
  }

ll e() {
  return -1;
}
ll target;
bool f(ll a){
  return a<target;
}

int main(){

  ll n,q;
  cin >> n >> q;

  vec a(n);
  for(ll i=0;i<n;i++)cin >> a[i];

  segtree<ll, op, e> S(a);

  vec ans;

  for(ll i=0;i<q;i++){
    ll t,l,r;
    cin >> t >> l >> r;
    if(t==1){
      S.set(l-1,r);
    }
    else if(t==2){
      ans.push_back(S.prod(l-1,r));
    }
    else{
      target=r;
      ans.push_back(S.max_right<f>(l-1)+1);
    }
  }

  for(ll i=0;i<ans.size();i++)cout << ans[i] << endl;

}

Measured memory_bytes: 11072
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    if S[3] == S[2] and S[4] == S[5]:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
n = int(input())
s = dict({})
for _ in range(n):
    data = input()
    if data not in s:
        s[data] = 1
    else:
        s[data] += 1

res_n = 0
res = []
for k, v in s.items():
    if v > res_n:
        res.clear()
        res.append(k)
        res_n = v
    elif v == res_n:
        res.append(k)

res.sort()
for r in res:
    print(r)


Measured memory_bytes: 32096
import sys
from collections import deque
sys.setrecursionlimit(10**7)
k = int(input())
ans = []
def bfs(que):
    finished = set()
    while que and len(ans) <= 10**5:
        x = que.popleft()
        ans.append(int(x))
        if x not in finished:
            finished.add(x)
            p = int(x[-1])
            if 1 <= p <= 8:
                que.append(x + str(p-1))
                que.append(x + str(p))
                que.append(x + str(p+1))
            elif p == 0:
                que.append(x + str(p))
                que.append(x + str(p+1))
            else:
                que.append(x + str(p-1))
                que.append(x + str(p))
que = deque([])
for i in range(1,10):
    que.append(str(i))
bfs(que)
ans.sort()
print(ans[k-1])

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

using namespace std;

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

  int n;
  cin >> n;
  vector<int64_t> x(n), y(n), h(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i] >> h[i];
  }
  for (int64_t i = 0; i <= 100; ++i) {
    for (int64_t j = 0; j <= 100; ++j) {
      bool ok = true;
      int k = 0;
      int64_t height;
      for (; k < n; ++k) {
        if (h[k] == 0) continue;
        height = h[k] + abs(i - x[k]) + abs(j - y[k]);
        break;
      }
      for (int k = 0; k < n; ++k) {
        if (h[k] == 0) {
          if (0 < height - abs(i - x[k]) - abs(j - y[k])) {
            ok = false;
            break;
          }
        } else if (h[k] + abs(i - x[k]) + abs(j - y[k]) != height) {
          ok = false;
          break;
        }
      }
      if (ok) {
        cout << i << " " << j << " " << height << "\n";
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256