akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<cctype>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;
int d[11][11],x[11],y[11],V=9999;
char m[22][22],*_;
void F(int x,int y)
{
	typedef pair<int,int>P;
	queue<P>q;
	P p;
	q.push(P(x,y));
	q.push(P(-1,-1));
	int r=0,f[22][22]={0},i=m[y][x]-'/',c;
	while(q.size()>1)
	{
		p=q.front();q.pop();
		x=p.first,y=p.second;
		if(x<0){++r;q.push(p);continue;	}
		if(m[y][x]=='x' || f[y][x]++)continue;
		if(m[y][x]=='/'||isdigit(m[y][x]))c=m[y][x]-'/',d[i][c]=d[c][i]=r;
		q.push(P(x+1,y));q.push(P(x-1,y));q.push(P(x,y+1));q.push(P(x,y-1));
	}
}
int main()
{
	int w,h,i,j,c;
	while(cin>>w>>h,w)
	{
		for(c=0,i=1;i<=h;++i)
		{
			cin>>m[i]+1;
			for(_=m[i]+1;_=strpbrk(_,"o*");++_)
			{
				if(*_=='o')*_='/';
				else *_=c+++'0';
				x[*_-'/']=_-m[y[*_-'/']=i];
			}
		}
		for(i=0;i<=h+1;++i)m[i][0]=m[i][w+1]='x';
		for(j=0;j<=w+1;++j)m[0][j]=m[h+1][j]='x';
		for(i=0;i<=c;++i)for(j=0;j<=c;++j)d[i][j]=V;
		for(i=0;i<=c;++i)F(x[i],y[i]);
		int r=V,s,a[]={0,1,2,3,4,5,6,7,8,9,10};
		do
		{
			for(s=i=0;i<c;++i)s+=d[a[i]][a[i+1]];
			r=min(r,s);
		}while(next_permutation(a+1,a+c+1));
		cout<<(r-V?r:-1)<<endl;
	}
	return 0;
}

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

int main(void) {
    int n;
    cin >> n;
    long long ans = 1;
    long long bad = 1;
    for (int i = 0; i < n; ++ i) {
        int x;
        cin >> x;
        ans *= 3;
        if (x % 2 == 0) bad *= 2;
    }
    cout << ans - bad << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
	ll X;
  	cin >> X;
  	ll ans = 0, acc = 0;
  	for(ll i = 1;;i++) {
    	acc += i;
      	ans += 1;
      	if (acc >= X) {
        	cout << ans << endl;
         	return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 256
#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-05-03 20:18:14
 **/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int flag = 0;
  for (auto e : vec) os << (flag++ ? ", " : "{") << e;
  return os << (vec.empty() ? "{}" : "}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int flag = 0;
  for (auto e : st) os << (flag++ ? ", " : "{") << e;
  return os << (st.empty() ? "{}" : "}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int flag = 0;
  for (auto e : mp) os << (flag++ ? ", " : "{") << e;
  return os << (mp.empty() ? "{}" : "}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

#pragma endregion kyomukyomupurin

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

  string s; cin >> s;

  if (s == "ABC") {
    cout << "ARC" << endl;
  } else {
    cout << "ABC" << endl;
  }

  return 0;
}

Measured memory_bytes: 3612
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;
using ll = long long;

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

int main()
{
	string SS,ST="";
	cin >> SS;

	deque<char> S;

	rep(i,SS.size()) S.push_back(SS[i]);

	int Q;
	cin >> Q;

	int T,X=0;

	int F;
	char C;

	for (int z = 1; z <= Q;++z) {
		cin >> T;
		if (T == 1) {
			++X;
		}
		else {
			cin >> F >> C;
			if (F == 1) {
				if (X % 2 == 1) { S.push_back(C); }
				else { S.push_front(C); }
			}
			else{
				if (X % 2 == 1) { S.push_front(C); }
				else { S.push_back(C); }
			}
		}
	}
	if (X % 2 == 1) {
		rep(i, S.size()) ST += S[i];
		reverse(ST.begin(),ST.end());
		cout << ST << endl;
	}
	else {
		rep(i, S.size()) cout << S[i];
	}

}

Measured memory_bytes: 1288
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
string itos(int N){
  stringstream ss;
  ss<<N;
  return ss.str();
}

int main(){
  int N, K;
  while(cin>>N>>K && N){
    int cur = 1;
    int ten[10] = {};
    ten[1] = 10;
    for(int i = 1; i < 9; i++) ten[i + 1] = ten[i] * 10;
    int dig = 1;
    string output;
    N--;
    while(N > 0){
      if(N - dig < 0){
        string s = itos(cur);
        output += s.substr(N);
      }
      N -= dig;
      cur++;
      if(ten[ dig ]==cur) dig++;
    }
    while(output.size() < K){
      output += itos(cur++);
    }
    cout<<output.substr(0, K)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;

int main() {
	string s;
	cin >> s;
	vector<int> ans;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'B' && ans.empty() == 1) {
			continue;
		}
		else if (s[i] == '0') {
			ans.push_back(0);
		}
		else if (s[i] == '1') {
			ans.push_back(1);
		}
		else {
			ans.pop_back();
		}
	}

	int n = ans.size();

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

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 100000000;
const ll half_inf = 0x3f3f3f3f;
const ll inf = 0x7fffffff;
const ll mod = 998244353;
const ll maxn = 2000005;

int main(){
	int n;
	scanf("%d",&n); 
	int l=n%10;
	if(l==3) printf("bon");
	else{
		if(l==0||l==1||l==6||l==8){
			printf("pon");
			
		}
		else{
			printf("hon");
		}
	}
	return 0;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using Graph = vector<vector<int>>;


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll modinv(ll a, ll m){
    ll b = m, u = 1, v = 0;
    while(b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if(u < 0) u += m;
    cout << u << endl;
    return u;
}

ll paty_counter(ll level, ll x){
    ll size = pow(2, level+2) - 3;
    ll pmi = pow(2, level) - 1;
    if(x == 0){
        return 0;
    }else if(level == 0){    
        return 1;
    }else{
        if(x <= (size - 1)/2){
            return paty_counter(level-1, x-1);
        }else{
            return pmi + 1 + paty_counter(level-1, x - pow(2, level+1) + 3 - 2);
        }
    }

}
 
int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    ll x;
    if(n/b >= 1){
        x = b-1;
    } else {
        x = n;
    }
    ll ans = floor(a * x / b) - a * floor(x / b);
    cout << ans <<endl;
}



Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

int main() {
  string S;
  cin >> S;
  
  long long int count = 0;
  long long int blackCount = 0;
  for (long long int i = S.length() - 1; i >= 0; i--) {
    if (S[i] == 'B') {
      count += S.length() - i - 1 - blackCount;
      blackCount++;
    }
  }
  
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 640
n,a,b,c,d=map(int,input().split())
a,b,c,d=a-1,b-1,c-1,d-1
s=input()
if a<b<c<d and '##' not in s[a:c] and '##' not in s[b:d]:
    print('Yes')
elif a<c<b<d and '##' not in s[a:c] and '##' not in s[b:d]:
    print('Yes')
elif a<b<d<c and '##' not in s[a:c] and '##' not in s[b:d] and '...' in s[max(b-1,0):d+2]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;cin>>n>>k;
  vector<vector<ll>>ed(n);
  rep(i,n-1){
    ll a,b;cin>>a>>b;
    a--;b--;
    ed[a].push_back(b);
    ed[b].push_back(a);
  }
  ll mod=1e9+7;
  vector<ll>mem(n,-1);
  ll res=1;
  mem[0]=k;
  function<void(ll,ll)> dfs=[&](ll now,ll pre){
    ll tk=k-2;
    if(pre==-1)tk++;
    for(auto nn:ed[now]){
      if(nn==pre)continue;
      mem[nn]=tk--;
      dfs(nn,now);
    }
  };
  dfs(0,-1);
  rep(i,n){
    res*=mem[i];
    res%=mod;
  }
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 12416
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, k;
vector<ll> a;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    a.resize(n);
    rep(i, n) cin >> a[i];
    vector<vector<int>> v(200000 + 1);
    rep(i, n)
    {
        v[a[i]].push_back(i);
    }
    vector<int> next(n);
    rep(i, n)
    {
        auto x = lower_bound(ALL(v[a[i]]), i + 1);
        if (x == v[a[i]].end())
        {
            next[i] = v[a[i]][0];
        }
        else
        {
            next[i] = *x;
        }
    }
    ll count = 1;
    int j = 0;
    while (j != n)
    {
        if (j >= next[j])
            count++;
        j = next[j] + 1;
    }
    k %= count;
    if (k == 0)
        return cout << "\n", 0;
    vector<int> ans;
    j = 0;
    k--;
    while (j!=n)
    {
        if (k > 0)
        {
            if (j >= next[j])
                k--;
            j = next[j] + 1;
        }
        else
        {
            if (j >= next[j])
            {
                ans.push_back(a[j]);
                j++;
            }
            else
                j = next[j] + 1;
        }
    }
    rep(i, ans.size())
    {
        cout << ans[i] << "\n";
    }
}


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

using namespace std;

const int MOD = 1000000007;

vector<int> f, invf;

int modpow(int x, int n, int mod) {
  int res = 1;
  while (n > 0) {
    if (n & 1) res = 1LL * res * x % mod;
    x = 1LL * x * x % mod;
    n >>= 1;
  }
  return res;
}

int comb(int a, int b) {
  return (1LL * f[a + b] * invf[a] % MOD) * invf[b] % MOD;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int X, Y;
  cin >> X >> Y;
  int a = (2 * X - Y) / 3, b = (2 * Y - X) / 3;
  if (a < 0 || b < 0 || (2 * X - Y) % 3 != 0 || (2 * Y - X) % 3 != 0) {
    cout << 0 << '\n';
    return 0;
  }
  int maxf = a + b + 1;
  f.assign(maxf, 1), invf.assign(maxf, 1);
  for (int i = 1; i < maxf; i++) {
    f[i] = 1LL * i * f[i - 1] % MOD;
  }
  invf[maxf - 1] = modpow(f[maxf - 1], MOD - 2, MOD);
  for (int i = maxf - 1; i > 0; i--) {
    invf[i - 1] = 1LL * i * invf[i] % MOD;
  }
  cout << comb(a, b) << '\n';
  return 0;
}


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

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N;
    vector<int> A;
    void input() {
        cin >> N;
        A.resize(N); cin >> A;
    }

    int cost(int x) {
        int ret = 0;
        for (int i = 0; i < N; i++) {
            ret += (A[i] - x) * (A[i] - x);
        }
        return ret;
    }

    void solve() {
        int ans = INT_MAX;
        for (int x = -100; x <= 100; x++) {
            ans = min(ans, cost(x));
        }
        cout << ans << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	String S = sc.next();
    	String[] s = S.split("");
    	int ans = 0;
    	for(int i=0; i<3; i++) {
    	    if(s[i].equals("1")) ans++;
    	}
    	System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <list>
#include <algorithm>

using namespace std;

void print(list<int> aList) {
    auto itor = aList.begin();
    //auto itor = aList.begin();
    cout << *itor;
    ++itor;
    while (itor != aList.end()) {
        cout << " " << *itor;
        ++itor;
    }
    cout << endl;
}
int main()
{
    list<int> aList;

    int n;
        string command;
        int x;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> command;
        if (command == "insert") {
            cin >> x;
            aList.push_front(x);
        }
        else if (command == "delete") {
            cin >> x;
            auto itor = find(aList.begin(), aList.end(), x);
            if (itor != aList.end()) {
                aList.erase(itor);
            }
        }
        else if (command == "deleteFirst") {
            aList.erase(aList.begin());
        }
        else if (command == "deleteLast") {
            auto itor = aList.end();
            --itor;
            aList.erase(itor);
        }
    }
    print(aList);
}




Measured memory_bytes: 34268
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define forn(i,a,n) for(int i=a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<lli,lli> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod = 1e9+7;
const int maxn = 1e5+5;

int main(){__
	int n;
	cin >> n;
	int a = 1000;
	while(a < n){
		a+=1000;
	}
	cout << a-n << endl;
	return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e6+7;
const ll mod = 1e9 + 9;
#define afdafafafdafaf y1;
int ar[maxn], n, m;
int ans[maxn];
int f[maxn];

char ch[maxn];
int ins = 0;
int main()
{
    scanf("%d%d", &n, &m);
    printf("%d\n", max(0, n - 2 * m));
    return 0;
}


Measured memory_bytes: 2304
n=int(input())
lr=[list(map(int,input().split())) for _ in range(n)]
lr.sort(key=lambda x:x[0])
# 右端がもっとも左にある問題
r0=0
tmpr=float('inf')
# 左端がもっとも右にある問題
l0=0
tmpl=0
for i,x in enumerate(lr):
  l,r=x
  if tmpl<l:
    l0=i
    tmpl=l
  if tmpr>r:
    r0=i
    tmpr=r
if l0==r0:
  ans=lr[r0][1]-lr[l0][0]+1
  tmp=0
  for i in range(n):
    if i==l0:continue
    l,r=lr[i]
    tmp=max(tmp,r-l+1)
  ans+=tmp
  print(ans)
  exit()
ans0=max(0,lr[r0][1]-lr[l0][0]+1)
tmp=0
for i in range(n):
  if i==l0 or i==r0:continue
  l,r=lr[i]
  tmp=max(tmp,r-l+1)
ans0+=tmp


import heapq
class pqheap:
  def __init__(self,key=None):
    self.p = list()
    self.q = list()
  def insert(self,x):
    heapq.heappush(self.p, x)
    return
  def erase(self,x):
    heapq.heappush(self.q, x)
    return
  def minimum(self):
    while self.q and self.p[0] == self.q[0]:
      heapq.heappop(self.p)
      heapq.heappop(self.q)
    return self.p[0] if len(self.p)>0 else None
pq=pqheap()

[pq.insert(x[1]) for i,x in enumerate(lr) if i!=l0 and i!=r0]
l1,r1=lr[r0]
l2,r2=lr[l0]
if pq.minimum():r2=min(r2,pq.minimum())
ans1=max(r1-l1+1,0)
ans1+=max(r2-l2+1,0)
for i,[l,r] in enumerate(lr):
  if i==l0 or i==r0:continue
  tmp=0
  l1=max(l1,l)
  pq.erase(r)
  tmp=max(r1-l1+1,0)
  if pq.minimum():
    r2=min(lr[l0][1],pq.minimum())
  else:
    l2,r2=lr[l0]
  tmp+=max(r2-l2+1,0)
  ans1=max(ans1,tmp)
print(max(ans1,ans0))


Measured memory_bytes: 30176
// #include <iostream>
// #include <vector>
// #include <algorithm>
// #define int long long
// using namespace std;

// struct Node {
// 	string name;
// 	int w, v;
// } a[1000010];

// bool cmp(Node a, Node b) {
// 	return a.v > b.v;
// }

// void work(int n, int k) {
// 	for(int i = 1; i <= n; ++i)
// 		cin >> a[i].name >> a[i].w >> a[i].v;
// 	stable_sort(a + 1, a + n + 1, cmp);
// 	int maxx = -1, pos = 1, ans = 0, maxp;
// 	while(k && pos <= n) {
// 		if(a[pos].w <= k) {
// 			k -= a[pos].w;
// 			ans += a[pos].w * a[pos].v;
// 			if(maxx < a[pos].w * a[pos].v)
// 				maxx = a[pos].w * a[pos].v, maxp = pos;
// 		}
// 		else {
// 			ans += a[pos].v * k;
// 			if(maxx < a[pos].v * k)
// 				maxx = a[pos].v * k, maxp = pos;
// 			k = 0;
// 		}
// 		++pos;
// 	}
// 	cout << ans << endl << a[maxp].name << ' ' << maxx << endl;
// } 

// signed main() {
// 	ios::sync_with_stdio(0);
// 	cin.tie(NULL);
// 	int n, k;
// 	while(cin >> n >> k) work(n, k);
// 	return 0;
// }

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

double dis[23][23];
int n, x, ans = 0;
double eps = 1e-7;

double calc(int a, int b) {
	double ret = 0;
	for(int i = 1; i <= x; ++i)
		ret += (dis[a][i] - dis[b][i]) * (dis[a][i] - dis[b][i]);
	return sqrt(ret);
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cin >> n >> x;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= x; ++j)
			cin >> dis[i][j];
	for(int i = 1; i <= n; ++i)
		for(int j = i + 1; j <= n; ++j) {
			double dist = calc(i, j);
			// cout << i << ' ' << j << ' ' << dist << endl;
			if(fabs(dist) - floor(dist) <= eps) ++ans;
		}
	cout << ans;
	return 0;
}

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

#define all(n) n.begin(),n.end()
#define ll long long

#define pb push_back
#define eb emplace_back
#define endl "\n"
#define pll pair<ll,ll>
#define ff first
#define ss second

using namespace std;
const ll maxn=2e6+120;
const ll maxx=1e16;
const ll mod=1e9+7;
const ll mod1=998244353;
vector<ll> adj[maxn];
ll dp[maxn];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if (fopen("TEAMS.INP","r"))
    {
        freopen("TEAMS.INP", "r", stdin);
        freopen("TEAMS.OUT", "w", stdout);
    }
    ll x;
    cin>>x;
    for (int i=1;i<maxn;i++)
    {
        if ((x*i)%360==0)
        {
            cout <<i;
            return 0;
        }
    }



}


Measured memory_bytes: 50536
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    int A,B,C; cin >> A >> B >> C;
    if(B-A==C-B) pr("YES");
    else pr("NO");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, l;
  cin >> n >> l;
  vector<string> vec;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    vec.push_back(str);
  }
  sort(vec.begin(), vec.end());
  for (auto i = vec.begin(); i != vec.end(); i++) cout << *i;
  cout << endl;
}

Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {

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

		String n = sc.next();

		if (n.contains("9")) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}
}

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

int main() {
  int x;
  cin >> x;
  
  for(int i = 0; i < 10; i++){
    x -= 200;
    if(x < 400){
      cout << 8 - i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3620
def dist(i, j):
    dx = x[i] - x[j]
    dy = y[i] - y[j]
    return pow(dx * dx + dy * dy, 0.5)


xys = []
x = []
y = []

n = int(raw_input())

for _ in range(n):
    xys.append(map(int, raw_input().split()))

for xy in xys:
    x.append(xy[0])
    y.append(xy[1])

result = 0.0

for i in range(n):
    for j in range(i, n):
        result += (dist(i, j)) * 2 / n

print(result)


Measured memory_bytes: 2692
#include<bits/stdc++.h>
#define ll long long int
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define inf 1e9

using namespace std;

ll min(ll a, ll b) {
	return (a <= b) ? a : b;
}

ll find(vector<ll> &h, ll n, ll k) {
	vector<ll> dp(n + 1);
	dp[1] = 0;

	for (ll i = 2; i <= n; i++) {
		dp[i] = inf;

		for (ll j = i - 1; j >= 1 && (i - j) <= k; j--)
			dp[i] = min(dp[i], abs(h[i] - h[j]) + dp[j] );
	}
	return dp[n];
}


int main() {


	fio

	ll n, k;
	cin >> n >> k;

	vector<ll> h(n + 1);

	for (ll i = 1; i <= n; i++)
		cin >> h[i];

	cout << find(h, n, k) << "\n";

}



Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>

using namespace std;

static const int MAX = 100;

struct store {
  string city;
  int score;
  int idx;

  bool operator < (const store &s) const {
    if ( city != s.city ) { 
      return city < s.city; 
    } else {
      return score > s.score;
    }
  }
};

int main(void) {
  int N;
  store r[MAX];
  char S[11];

  scanf("%d", &N);

  for ( int i = 0; i < N; i++ ) {
    scanf("%s %d", S, &r[i].score);
    r[i].city = S;
    r[i].idx = i + 1;
  }

  sort(r, r + N);

  for ( int i = 0; i < N; i++) {
    printf("%d\n", r[i].idx);
  }

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;


int main() {
	int R[MAX],n;
	
	cin >> n;
	
	int maxv = -2000000000;
	int minv;
	cin >> minv;

	for (int i = 1; i < n; i++) {
		int R;
		cin >> R;
		maxv = max(maxv, R - minv);
		minv = min(minv,R);
	}

	cout << maxv << endl;

	return 0;
}


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

using namespace std;
using ll = long long;
#define each(i, mp) for(auto& i:mp)

int main() {
    string s;
    cin >> s;
    map<ll, ll> mp;
    mp[0] = 1;
    reverse(s.begin(), s.end());
    ll now = 0, ten = 1;
    each(e, s) {
        now = (now + (e - '0') * ten) % 2019;
        ten *= 10;
        ten %= 2019;
        mp[now]++;
    }
    ll ans = 0;
    each(e, mp) {
        ans += e.second * (e.second - 1) / 2;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3792
#include <stdio.h>

int main (){
int rangeA, rangeB, kelipatan;
int jumlah = 0;
scanf("%d %d %d", &rangeA, &rangeB, &kelipatan);

for(int i=rangeA; i<=rangeB; i++){
	if(i%kelipatan==0){
		jumlah++;
	}

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

Measured memory_bytes: 1700
import static java.util.Arrays.deepToString;

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc = new Scanner(System.in);
	public void run() {
		for (;sc.hasNext();) {
			int my1 = sc.nextInt();
			int my2 = sc.nextInt();
			int enemy1 = sc.nextInt();
			boolean[] used = new boolean[11];
			used[my1] = true;
			used[my2] = true;
			used[enemy1] = true;
			int all = 0;
			int safe = 0;
			for (int i = 1; i <= 10; i++) if (!used[i]) {
				all++;
				if (my1 + my2 + i <= 20) safe++;
			}
			if (safe * 2 >= all) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
	char solve(int[][] a) {
		char[] s = {'d', 'o', 'x'};
		for (int side = 1; side <= 2; side++) {
			for (int i = 0; i < 3; i++) {
				if (a[i][0] == side && a[i][1] == side && a[i][2] == side) return s[side];
				if (a[0][i] == side && a[1][i] == side && a[2][i] == side) return s[side];
			}
			if (a[0][0] == side && a[1][1] == side && a[2][2] == side) return s[side];
			if (a[0][2] == side && a[1][1] == side && a[2][0] == side) return s[side];
		}
		return 'd';
	}
}

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

int main() {
	long long n, k;
	cin >> n >> k;
	long long b[2][60] = {};
	for (int i = 0; i < n; i++) {
		long long a;
		cin >> a;
		bitset<60> a_bit(a);
		for (int j = 0; j < 60; j++) {
			b[1-a_bit[j]][j]++;
		}
	}
	bitset<60> k_bit(k);

	long long dp[61][2]; fill((long long *)dp, (long long *)dp + sizeof(dp)/sizeof(long long), -1);
	dp[60][0] = 0;
	for (int i = 60; i > 0; i--) {
		const int D = k_bit[i-1];
		for (int smaller = 0; smaller < 2; smaller++) {
			if (dp[i][smaller] == -1) continue;
			if (smaller == 1) {
				long long x = dp[i][1] * 2 + max(b[0][i-1], b[1][i-1]);
				dp[i-1][1] = max(dp[i-1][1], x);
			} else {
				long long x = dp[i][0] * 2 + b[D][i-1];
				dp[i-1][0] = max(dp[i-1][0], x);
				if (D == 1) dp[i-1][1] = max(dp[i-1][1], dp[i][0] * 2 + b[0][i-1]);
			}
		}
	}
	long long ans = max(dp[0][0], dp[0][1]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
long long a,b,c,d,e,f,g, res, t;
int main(){
    scanf("%lld%lld%lld%lld%lld%lld%lld",&a,&b,&c,&d,&e,&f,&g);
    res = b;
    t = a%2 + d%2 + e%2;
    if(t>=2 && a&&d&&e){
        a--,d--,e--;
        res+=3;
    }
    printf("%lld\n",res+a/2*2+d/2*2+e/2*2);
}

Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int AMAX = 100000;
int main() {
  int n;
  scan(n);
  vi a(n);
  scan(a);
  vi cnt(AMAX + 1, 0);
  rep (i, n) {
    cnt[a[i]] += 1;
  }
  int erase_cnt = 0;
  rep (i, AMAX + 1) {
    erase_cnt += max(0, cnt[i] - 1);
  }
  if (erase_cnt & 1) {
    erase_cnt += 1;
  }
  print(n - erase_cnt);

  return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	private class HashSet {

		private int M = 1046527;
		private String[] H = new String[M];
		
		private int getChar(char ch) {
			if (ch=='A') return 1;
			else if (ch=='C') return 2;
			else if (ch=='G') return 3;
			else if (ch=='T') return 4;
			else return 0;
		}
		
		private int getKey(String str) {
			int sum = 0, p = 1;
			for (int i = 0; i < str.length(); i++) {
				sum += p*(getChar(str.charAt(i)));
				p *= 3;
			}
			return sum;
		}

		private int h1(int key) {return key % M;}
		private int h2(int key) {return 1 + (key % (M-1));}

		public boolean find(String str) {
			int key, i, h;
			key = getKey(str);
			for (i = 0 ;; i++) {
				h = (h1(key) + i * h2(key)) % M;
				if (H[h] != null && H[h].equals(str)) return true;
				else if (H[h] == null || H[h].length() == 0) return false;
			}
		}
		
		public void insert(String str) {
			int key, i, h;
			key = getKey(str);
			for (i = 0 ;; i++) {
				h = (h1(key) + i * h2(key)) % M;
				if (H[h] != null && H[h].equals(str)) return;
				else if (H[h] == null || H[h].length() == 0) {
					H[h] = new String(str);
					return;
				}
			}
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		HashSet set = new HashSet();
		int n = Integer.parseInt(reader.readLine());
		for (int i = 0; i < n; i++) {
			StringTokenizer st = new StringTokenizer(reader.readLine());
			String cmd = st.nextToken();
			String str = st.nextToken();
			if (cmd.equals("insert")) {
				set.insert(str);
			} else if (cmd.equals("find")) {
				if (set.find(str)) {
					System.out.println("yes");
				} else {
					System.out.println("no");
				}
			}
		}
		reader.close();
	}
}


Measured memory_bytes: 125132
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
long long mod=998244353;
int main(){
	int h,w,m;
	cin>>h>>w>>m;
	set<pair<int,int> > se;
	vector<pair<int,int> > tate(300000);
	vector<pair<int,int> > yoko(300000);
	for(int i=0;i<h;i++){
		tate[i].first=0;
		tate[i].second=i;
	}
	for(int i=0;i<w;i++){
		yoko[i].first=0;
		yoko[i].second=i;
	}
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		tate[a].first++;
		yoko[b].first++;
		se.insert(make_pair(a,b));
	}
	sort(tate.rbegin(),tate.rend());
	sort(yoko.rbegin(),yoko.rend());
	int ma=tate[0].first;
	int mb=yoko[0].first;
	for(int i=0;i<h;i++){
		if(tate[i].first!=ma){
			break;
		}
		for(int j=0;j<w;j++){
			if(yoko[j].first==mb){
				if(se.find(make_pair(tate[i].second,yoko[j].second))==se.end()){
					cout<<ma+mb<<endl;
					return 0;
				}
			}else{
				break;
			}
		}
	}
	cout<<ma+mb-1<<endl;
	return 0;
}


Measured memory_bytes: 21620
#include <algorithm>
#include <cassert>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <tuple>
#include <vector>

using namespace std;

namespace
{

int reverse(int n)
{
	int res = 0;
	while (n != 0) {
		res *= 10;
		res += n % 10;
		n /= 10;
	}

	return res;
}

long long gcd(long long a, long long b)
{
	return b ? gcd(b, a % b) : a;
}

long long lcm(long long a, long long b)
{
	return (a / gcd(a, b)) * b;
}

}

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

	long long res = 1;
	for (int i = 0; i != n; ++i) {
		long long t;
		std::cin >> t;
		res = lcm(res, t);
	}

	std::cout << res << std::endl;
	return 0;
}


Measured memory_bytes: 256
def submit():
    h, w = map(int, input().split())
    costs = [list(map(int, input().split())) for _ in range(10)]
    a = [list(map(int, input().split())) for _ in range(h)]

    # i, j間の最短距離を求める
    dist = {(i, j): float('inf') for i in range(10) for j in range(10)}
    for i in range(10):
        for j in range(10):
            dist[(i, j)] = costs[i][j]

    for k in range(10):
        for i in range(10):
            for j in range(10):
                dist[(i, j)] = min(dist[(i, j)], dist[(i, k)] + dist[(k, j)])

    ans = 0
    for i in range(h):
        for j in range(w):
            if a[i][j] < 0:
                continue    
            ans += dist[(a[i][j], 1)]
    print(ans)


submit()

Measured memory_bytes: 3444
#include "bits/stdc++.h"
using namespace std;

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

    int n,m;
    long long ans = 0;
    cin >> n >> m;
    int now = 0;
    map<int, int> mp;
    mp[0]++;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        now += a;
        now %= m;
        ans += mp[now];
        mp[now]++;
    }

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

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

int main() {
  ll n, a, b;cin >> n >> a >> b;
  if((b-a)%2LL==0){
    cout << (b-a)/2LL << endl;
    return 0;
  }
  ll ans = 0;
  if(a-1<n-b){
    ans = a;
    b-=a;
    ans+=(b)/2LL;
  }
  else{
    ans= n-b;
    a+=n-b;
    ans+=(n-a+1)/2LL; 
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=100+10;
int f[maxn][maxn][maxn],sum[maxn][maxn];
int i,j,k,l,r,u,d,t,n,m,ex,ey,ans,up,down,left,right;
char ch;
char get(){
	char ch=getchar();
	while (ch!='.'&&ch!='o'&&ch!='E') ch=getchar();
	return ch;
}
int getsum(int a,int b,int x,int y){
	return sum[x][y]-sum[a-1][y]-sum[x][b-1]+sum[a-1][b-1];
}
int main(){
	scanf("%d%d",&n,&m);
	fo(i,1,n)
		fo(j,1,m){
			ch=get();
			if (ch=='E'){
				ex=i;
				ey=j;
			}
			else if (ch=='o') sum[i][j]++;
		}
	fo(i,1,n)
		fo(j,1,m)
			sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
	fo(i,0,n)
		fo(j,0,m)
			fo(k,0,m)
				f[i][j][k]=-100000000;
	f[0][0][0]=0;
	fo(u,0,n){
		if (ex-u<1) break;
		fo(d,0,n){
			if (ex+d>n) break;
			up=max(ex-u,1+d);
			down=min(ex+d,n-u);
			if (up>down) continue;
			fo(l,0,m){
				if (ey-l<1) break;
				fo(r,0,m){
					if (ey+r>m) break;
					left=max(ey-l,1+r);
					right=min(ey+r,m-l);
					if (left>right) continue;
					ans=max(ans,f[d][l][r]);
					if (u+d<n-ex) f[d+1][l][r]=max(f[d+1][l][r],f[d][l][r]+getsum(ex+d+1,left,ex+d+1,right));
					if (l+r<ey-1) f[d][l+1][r]=max(f[d][l+1][r],f[d][l][r]+getsum(up,ey-l-1,down,ey-l-1));
					if (l+r<m-ey) f[d][l][r+1]=max(f[d][l][r+1],f[d][l][r]+getsum(up,ey+r+1,down,ey+r+1));
					if (u+d<ex-1) f[d][l][r]=max(f[d][l][r],f[d][l][r]+getsum(ex-u-1,left,ex-u-1,right));
				}
			}
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 4992
#include <iostream>
using namespace std;
const int dorder[8][8] = {
	{1, 2, 1, 2, 1, 4, 1, 4},
	{1, 2, 1, 4, 1, 4, 1, 2},
	{1, 4, 1, 2, 1, 2, 1, 4},
	{1, 4, 1, 4, 1, 2, 1, 2},
	{2, 1, 2, 1, 4, 1, 4, 1},
	{2, 1, 4, 1, 4, 1, 2, 1},
	{4, 1, 2, 1, 2, 1, 4, 1},
	{4, 1, 4, 1, 2, 1, 2, 1},
};

int main () {
	while (true) {
		int minremain = 0;
		int minidx = -1;
		int p[8];
		for (int i = 0; i < 8; i++) {
			cin >> p[i];
			minremain += p[i];
		}
		if (!cin.good()) break;
		
		for (int i = 0; i < 8; i++) {
			int rem = 0;
			for (int j = 0; j < 8; j++) {
				rem += max(0, p[j] - dorder[i][j]);
			}
			if (rem < minremain) {
				minremain = rem;
				minidx = i;
			}
		}
		cout << dorder[minidx][0];
		for (int i = 1; i < 8; i++) {
			cout << ' ' << dorder[minidx][i];
		}
		cout << endl;
	}
	return 0;
}

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

int sheet[101][101];

int main(){
  
  int r, c;
  cin >> r >> c;
  for(int i=0; i<r; i++){
    for(int j=0; j<c; j++){
      cin >> sheet[i][j];
      sheet[r][j] += sheet[i][j];
      sheet[i][c] += sheet[i][j];
      sheet[r][c] += sheet[i][j];
    }
  }

  for(int i=0; i<r+1; i++){
    for(int j=0; j<c+1; j++){
      cout << sheet[i][j];
      if(j!=c) cout << " ";
    }
    cout << endl;
  }

  return 0;
}

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

using namespace std;

int main(void) {
	int i = 0, num, R = 0, B = 0;
	string str;
	cin >> num >> str;
	for (; i < num; i++) {
		if (str[i] == 'R')
			R++;
		else
			B++;
	}
	if (R > B)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

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

using namespace std;

using ll = long long;

const int MX = 100 * 1000 + 7;

ll a[MX], b[MX];

ll f(ll x, ll y) {
    return (y - (x % y)) % y;
}

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    ll ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        a[i] += ans;
        ans += f(a[i], b[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

l_sum = [0]
s= 0
for i in range(n):
    s += a[i]
    l_sum.append(s)

c_sum = Counter(l_sum)

# print(c_sum)
ans = 0
for i in c_sum:
    if c_sum[i] > 1:
        ans += c_sum[i] * (c_sum[i] - 1) // 2

print(ans)

Measured memory_bytes: 41696
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<set>
#include<queue>
#include<vector>
#include<cstdio>
#include<map>
#include<iomanip>
using namespace std;
int a[333333];
int main()
{
  int n,ans=0,cnt=0;
  string s;
  cin>>n>>s;
  for(int i=1;i<n;i++)
    if(s[i]=='E')
      cnt++;
  ans=cnt;
  for(int i=1;i<n;i++){
    if(s[i-1]=='W')
      cnt++;
    if(s[i]=='E')
      cnt--;
    ans=min(ans,cnt);
  }
  cout<<ans;
  return 0;
}


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

int main(){
	int a,b;
	cin >> a >> b;
	int ans = 0;
	for(int i = a; i <= b; ++i){
		int x,y,z,w;
		x = i/10000;
		y = ((i/1000)%10);
		z = (i/10)%10;
		w = i%10;
		if(x==w && y==z) ++ans;
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    int curr = 0;
    int ans = 0;
    for(int i=0;i<n-1;i++)
    {
        if( h[i] >= h[i+1])
        {
            curr++;
            ans = max( ans , curr);
        }
        else curr =0;
    }
    cout<<ans;
}

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


int main() {
    int N,D,X;
    cin>>N>>D>>X;
    int A[N];
    rep(i,N)cin>>A[i];
    int count=N+X;
    for(int i=0;i<N;i++){
        int j=1;
        while(1+A[i]*j<=D){
            count++;
            j++;
        }
    }
    cout <<count <<endl;
}

Measured memory_bytes: 256
"""#################################################################
【ABC116】
B_Collatz_Problem
#################################################################"""

#インポート
import sys

#入力用
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def IS(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def SS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()

lst = []
lst.append(II())
i = 1
while 0==0:
    if lst[i-1] % 2 == 0:
        lst.append(lst[i-1] / 2)
    else:
        lst.append(3 * lst[i-1] + 1)
    if lst.count(lst[i]) == 2:
        print(i+1)
        break
    i += 1

Measured memory_bytes: 3064
#include <iostream>
#include<vector>
#include<cmath>
using namespace std;

int main()
{
  int N,D;
  cin>>N>>D;

  vector<vector<int> > X(N, vector<int>(D));
  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
      cin>>X.at(i).at(j);
    }
  }

  int ans = 0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      int tmp = 0;
      int tmp2 = 0;
      double tmp3 = 0;
      int tmp4 = 0;
      for(int k=0;k<D;k++){
        tmp = abs(X.at(i).at(k)-X.at(j).at(k));
        tmp2 += tmp * tmp;
      }
      tmp3 = sqrt(tmp2);
      tmp4 = tmp3;
      if(tmp3 - tmp4 == 0){
        ans += 1;
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
N = int(input())
X = []
for i in range(N):
  X.append(list(map(int, input().split())))
  
dp = [[0] * 3 for i in range(N+1)]

for i in range(1,N+1):
  dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + X[i-1][0]
  dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + X[i-1][1]
  dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + X[i-1][2]
  
print(max(dp[N]))

Measured memory_bytes: 77400
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String numStr = sc.nextLine();
		String[] numArr = numStr.split(" ");
		int numA = Integer.parseInt(numArr[0]);
		int numB = Integer.parseInt(numArr[1]);
		
		System.out.println(existNumber(numA, numB));
	}
	
	private static String existNumber(int numA, int numB) {
		if ((numA * numB) % 2 == 0) {
			return "No";
		}
		return "Yes";
	}
}

Measured memory_bytes: 23764
let () = Scanf.scanf "%d\n" @@ fun n ->
  let acc = Array.make_matrix 10 10 0 in
  for i = 1 to n do
    let s = string_of_int i in
    let h = Char.code s.[0] - Char.code '0' in
    let l = Char.code s.[String.length s - 1] - Char.code '0' in
    acc.(h).(l) <- 1 + acc.(h).(l)
  done;
  Printf.printf "%d\n" @@
  Array.fold_left (Array.fold_left ( + )) 0 @@
  Array.init 10 @@ fun i ->
    Array.init 10 @@ fun j ->
      acc.(i).(j) * acc.(j).(i)


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  ll x, y; cin >> x >> y;
  if (abs(x - y) <= 1) cout << "Brown" << "\n";
  else cout << "Alice" << "\n";
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A=new int[N];
        for(int i=0; i<N; i++){
            A[i]=sc.nextInt();
        }

        long res=0;
        int count = 0;
        boolean[] amari=new boolean[N];

        for(int i=0; i<N; i++){
            if(A[i]!=0&&amari[i]){
                A[i]++;
            }
            int h = A[i]/2;
            if(A[i]%2==1){
                amari[Math.min(i+1,N-1)] = true;
            }
            res = res + h;

        }
        
        System.out.println(res);
        
        }
     
    }

Measured memory_bytes: 59748
n = int(input())
a_list = [int(input()) for _ in range(n)]
sorted_a_list = sorted(a_list)
max_num = sorted_a_list[-1]
second_max_num = sorted_a_list[-2]

result = [0]*n
for i in range(n):
    if a_list[i] == max_num:
        result[i] = second_max_num
    else:
        result[i] = max_num

for i in range(n):
    print(result[i])

Measured memory_bytes: 15712
#include <stdio.h>
#include <string.h>
int main(void)
{
    int  a,b[2000],i,j,n=0,m,x,y,z=0;
    char c[100],s[100];

    scanf("%s",c);
    n=strlen(c);
    for (size_t i = 0; i < n/2; i++)
    {
      if(c[i]!=c[n-1-i]) z++;
    }
    printf("%d\n",z);

    
      return 0;
}

Measured memory_bytes: 128
def main():
    N, K = list(map(int, input().split(' ')))
    P = list(map(int, input().split(' ')))
    means = [(p + 1) / 2 for p in P]
    max_mean = sum(means[:K])
    current_mean = max_mean
    next_head = K
    while next_head < N:
        diff = means[next_head] - means[next_head - K]
        current_mean += diff
        max_mean = max([max_mean, current_mean])
        next_head += 1
    print(max_mean)


if __name__ == '__main__':
    main()


Measured memory_bytes: 25060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A;
  string str1;
  cin>>str1;
  A=str1.size();
  for(int i=0; i<A; i++)
    if (str1.at(i)=='?'){
      str1.replace(i,1,"D");
    }
  cout<<str1<<endl;
}

Measured memory_bytes: 3728