akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=40010,Mo=998244353;
int s,L;
char a[N],b[N];
int A[N],B[N],rev[N],fac[N],inv[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline int Pow(int x,int y) {
    int ret=1;
    while(y) {
	if(y&1) ret=1LL*ret*x%Mo;
	x=1LL*x*x%Mo,y>>=1;
    }
    return ret;
}
inline void NTT(int *a,int n,int f) {
    for(int i=0;i<n;i++) if(i<rev[i]) swap(a[i],a[rev[i]]);
    for(int i=1;i<n;i<<=1) {
	int wn=Pow(3,(Mo-1)/(i<<1)),x,y;
	for(int j=0;j<n;j+=i<<1)
	    for(int k=0,w=1;k<i;k++,w=1LL*w*wn%Mo) {
		x=a[j+k],y=1LL*a[j+k+i]*w%Mo;
		a[j+k]=(x+y)%Mo,a[j+k+i]=(x-y)%Mo;
	    }
    }
    if(f==1) return;
    reverse(a+1,a+n);
    int Inv=Pow(n,Mo-2);
    for(int i=0;i<n;i++) a[i]=1LL*a[i]*Inv%Mo;
}
inline void mul(int *a,int *b,int t) {
    NTT(a,s,1);
    if(b!=a) NTT(b,s,1);
    for(int i=0;i<s;i++) a[i]=1LL*a[i]*b[i]%Mo;
    NTT(a,s,-1);
    if(b!=a) NTT(b,s,-1);
    for(int i=t+1;i<s;i++) a[i]=0;
}
int main() {
    scanf("%s%s",a,b);
    int n=strlen(a),x=0,y=0,ans=0;
    for(int i=0;i<n;i++)
	if(a[i]=='1') {
	    if(b[i]=='1') ++x;
	    else ++y;
	}
    fac[0]=1;
    for(int i=1;i<=n;i++) fac[i]=1LL*fac[i-1]*i%Mo;
    inv[n]=Pow(fac[n],Mo-2);
    for(int i=n;i;i--) inv[i-1]=1LL*inv[i]*i%Mo;
    for(s=1,L=0;s<=x+x;s<<=1) L++;
    for(int i=0;i<s;i++) rev[i]=((rev[i>>1]>>1)|(i&1)<<L-1);
    A[0]=1;
    for(int i=0;i<=x;i++) B[i]=inv[i+1];
    int t=y;
    while(t) {
	if(t&1) mul(A,B,x);
	mul(B,B,x),t>>=1;
    }
    for(int i=0;i<=x;i++) ans=(ans+A[i])%Mo;
    cout<<(1LL*ans*fac[x]%Mo*fac[y]%Mo*fac[x+y]%Mo+Mo)%Mo;
    return 0;
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int n;
long long bit[500005];

long long query(int i) {
    long long ret = 0;
    for (; i>0; i-=i&-i)
        ret += bit[i];
    return ret;
}

void update(int i, int x) {
    for (; i<=n; i+=i&-i)
        bit[i] += x;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int q;
    cin >> n >> q;
    for (int i=1; i<=n; i++) {
        int a;
        cin >> a;
        update(i, a);
    }
    for (int i=0; i<q; i++) {
        int t, x, y;
        cin >> t >> x >> y;
        if (t == 0)
            update(x+1, y);
        else
            cout << query(y) - query(x) << "\n";
    }

    return 0;
}


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


int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  int N, K; cin >> N >> K;
  vector<int> h(N);
  for (int i = 0; i < N; i++) cin >> h.at(i);
  sort(h.begin(), h.end());
  int v = INT_MAX;
  for (int i = 0; i+K-1 < N; i++) {
    v = min(v, h.at(i+K-1) - h.at(i));
  }
  cout << v << endl;

  return 0;
}



Measured memory_bytes: 640
#include <iostream>

#define MAX 100005
#define NIL -1

using namespace std;

struct Node {
	int parent;
	int left;
	int right;
};

Node T[MAX];
int n, D[MAX];

void print(int u)
{
	int i, c;
	cout << "node " << u << ": ";
	cout << "parent = " << T[u].parent << ", ";
	cout << "depth = " << D[u] << ", ";

	if (T[u].parent == NIL) cout << "root, ";
	else if (T[u].left == NIL) cout << "leaf, ";
	else cout << "internal node, ";

	cout << "[";

	for (i = 0, c = T[u].left; c != NIL; i++, c = T[c].right)
	{
		if (i) cout << ", ";
		cout << c;
	}
	cout << "]" << endl;
}

int rec(int u, int p)
{
	D[u] = p;
	if (T[u].right != NIL) rec(T[u].right, p);
	if (T[u].left != NIL) rec(T[u].left, p + 1);
}

int main()
{
	int i, j, d, v, c, l, r;
	cin >> n;
	for (i = 0; i < n; i++) T[i].parent = T[i].left = T[i].right = NIL;

	for (i = 0; i < n; i++)
	{
		cin >> v >> d;
		for (j = 0; j < d; j++)
		{
			cin >> c;
			if (j == 0)T[v].left = c;
			else T[l].right = c;
			l = c;
			T[c].parent = v;
		}
	}

	for (i = 0; i < n; i++)
	{
		if (T[i].parent == NIL) r = i;
	}

	rec(r, 0);

	for (i = 0; i < n; i++) print(i);
	return 0;
}


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

long long n;
string s;
vector<vector<long long>> v;

long long solve();

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

  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0;
  v.resize(10);
  for(int i = 0; i < n; ++i) v[s[i] - '0'].push_back(i);
  for(int i = 0; i < 10; ++i)
    for(int j = 0; j < 10; ++j)
      for(int k = 0; k < 10; ++k) {
        long long now = 0;
        if(v[i].size() == 0) continue;
        now = v[i][0];
        auto it =
            upper_bound(v[j].begin(), v[j].end(), now);
        if(it == v[j].end()) continue;
        now = *it;
        it = upper_bound(v[k].begin(), v[k].end(), now);
        if(it == v[k].end()) continue;
        ++ans;
      }
  return ans;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const int INF=1e9;
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; }



int main(int argc, char const *argv[]) {
  string s;
  int n;
  std::cin >> n >> s;
  int r=0,b=0;
  for(int i=0; i<s.size(); i++){
    if(s[i]=='R') r++;
    else b++;
  }

  if(r>b)std::cout << "Yes" << '\n';
  else std::cout << "No" << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  int player=0;
  int ba=0;
  char huda;
  while(1){
    int c[100]={0};
    cin >> n;
    if(n==0) break;
    for(int i=0;i<100;i++){
      cin >> huda;
      if(player==n){
	player=0;
      }
      if(huda=='M'){
	c[player]++;
      }
      else if(huda=='S'){
	ba+=c[player]+1;
	c[player]=0;
      }
      else{
	c[player]+=ba+1;
	ba=0;
      }
      player++;
    }
    sort(c,c+n);
    for(int i=0;i<n;i++){
      cout << c[i] << " ";
    }
    cout << ba     << endl;
    player=0;
    ba=0;
  }
}

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

int main() {
  char S[3], T[3];
  cin >> S >> T;
  int result = 0;
  for (int i = 0; i < 3; i++) {
    if (S[i] == T[i]) result++;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define double long double
#define int long long 
#define f(z) for(int i=1;i<=z;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
int cl(int n ,int m) { if(n%m)return n/m + 1 ;else return n/m ;}
int pw(int a,int b,int M){a%=M;int r=1;while(b>0){if(b&1)r=r*a%M;a=a*a%M;b>>=1;}return r;}
#define mod  1000000007
#define T() int TT; cin>>TT; while(TT--)
#define P pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pr(r) cout <<"Case #"<<r <<": " ;

const int N = 1e6 + 5 ;
string num( int x)
{
	return (x>=30) ? "HII" : "BYE" ;
}
signed main(){
	int n; 
	
	cin >> n; 
	cout <<  ( (n>=30) ? "Yes" : "No" ) ; 
}


Measured memory_bytes: 3604
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

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

    int n;
    cin >> n;

    cout << (n << (n & 1)) << endl;

    return 0;
}

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

int main(void){
 
  int a,b;
  
  cin >> a >> b;
  
  if(a * b % 2 == 0){
    cout << "Even" << endl;
  }
  else{
    cout << "Odd" << endl;
  }
  
  
  
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int inf = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int ans = 0;
    rep(i,0,n) {
        rep(j,i+1, n) {
            ans += a[i] * a[j];
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
#define N 200200

long long v[N];
long long ans;
int i, n;
int main(){
    cin >> n;
    for (i = 0; i < n; ++i) {
        cin >> v[i];
    }
    if (n == 1) {
        cout << 0;
        return 0;
    }
    ans = 0;
    for (i = 1; i < n; ++i) {
        if (v[i] < v[i - 1]){
            ans += v[i - 1] - v[i];
            v[i] = v[i - 1];
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 5164
integer(16) N
integer(16) k
integer(16) ans
read*,N
ans=0
do k=1,N-1
  if(k**2+2*k>N)exit
  if(mod(N-k,k)==0)then
    ans=ans +(N-k)/k
  end if
end do
print"(i0)",ans
end

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    ll n,m,s[2000],t[2000],dp[2001][2001],mod=1e9+7;
    cin>>n>>m;
    rep(i,n) cin>>s[i];
    rep(i,m) cin>>t[i];
    rep(i,n+1)rep(j,m+1) dp[i][j]=1;
    rep(i,n)rep(j,m){
        if(s[i]==t[j]) dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1])%mod;
        else dp[i+1][j+1]=(dp[i][j+1]+dp[i+1][j]-dp[i][j]+mod)%mod;
    }
    cout<<dp[n][m];
}

Measured memory_bytes: 31616
S = str(input())
S_len = int(len(S))
zero_start = '01'*int(S_len/2)
one_start = '10'*int(S_len/2)
if S_len % 2 == 1:
    # print(zero_start, one_start)
    zero_start = int(zero_start + '0', 2)
    one_start = int(one_start + '1', 2)
else:
    zero_start = int(zero_start, 2)
    one_start = int(one_start, 2)

# print(zero_start, one_start)
# 異なっている部分が １ になった文字列
tmp_z = format(int(S, 2) ^ zero_start, 'b')
z_count = 0
for i in tmp_z:
    if i == '1':
        z_count += 1

tmp_o = format(int(S, 2) ^ one_start, 'b')
o_count = 0
for i in tmp_o:
    if i == '1':
        o_count += 1
# print(z_count, o_count)
if z_count > o_count:
    print(o_count)
else:
    print(z_count)

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n+2);
    for (int i = 1; i < n+1; ++i) cin >> a.at(i);
    int total = 0;
    rep(i,n+1) {
        total += abs(a.at(i+1) - a.at(i));   
    }

    vector<int> ans(n);
    rep(i,n) {
        if (
            (a.at(i) <= a.at(i+1) && a.at(i+1) <= a.at(i+2)) ||
            (a.at(i+2) <= a.at(i+1) && a.at(i+1) <= a.at(i))
        ) {
            ans.at(i) = total;
        }
        else {
            ans.at(i) = total - 2 * min(abs(a.at(i+1) - a.at(i)), abs(a.at(i+2) - a.at(i+1)));
        }
    }

    rep(i,n) cout << ans.at(i) << endl;
    return 0;
}

Measured memory_bytes: 4032
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// ルート(切り捨て)
long long
fSqrtL(
	long long plVal				// <I> 値 1～
)
{
	int liVal;

	// 正方形(辺の２乗)を１ずつ削る
	for (liVal = 1; plVal > 0; liVal++) {
		plVal -= liVal * 2 + 1;
	}

	return liVal - 1;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// N取得
	long long llN;
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%lld", &llN);

	// ルート
	long long llR = fSqrtL(llN);

	// 約数取得
	long long llM = 0;
	while (1) {
		if (llN % llR == 0) {
			llM = llN / llR;
			break;
		}
		else {
			llR--;
		}
	}

	// 桁数取得
	int liK = 0;
	while (llM > 0) {
		llM /= (long long)10;
		liK++;
	}

	// 結果セット
	sprintf(lc1Out, "%d\n", liK);

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



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

int main(){
  string s;
  cin >> s;
  int l = s.length();
  int t = l/2;
  int count = 0;
  for(int i = 0;i < t;i++){
    if(s[i] == s[l-1-i]){}
    else count++;
  }
  cout << count << endl;
   
}

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

int main() {
    int N; cin >> N;
    vector<int> A(3);
    for(int i = 0; i < 3; ++i) cin >> A[i];
    vector<pair<int, int>> query;
    for(int i = 0; i < N; ++i) {
        string S; cin >> S;
        query.emplace_back(S[0] - 'A', S[1] - 'A');
    }
    vector<int> ans, tmp;
    auto dfs = [&](auto &&dfs, int i) {
        if(!ans.empty() or A[0] < 0 or A[1] < 0 or A[2] < 0) return;
        if(i == N) { ans = tmp; return; }
        auto[x, y] = query[i];
        for(int _ = 0; _ < 2; ++_) {
            A[x]++, A[y]--, tmp.push_back(x);
            dfs(dfs, i + 1);
            A[x]--, A[y]++, tmp.pop_back();
            swap(x, y);
        }
    };
    dfs(dfs, 0);
    if(ans.empty()) {
        cout << "No" << '\n';
    } else {
        cout << "Yes" << '\n';
        for(auto &i : ans) cout << "ABC"[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 11144
import math

pi=math.pi

a,b,si=map(float,input().split())

S=(1/2)*a*b*math.sin(math.radians(si))
c2=a*a+b*b-2*a*b*math.cos(math.radians(si))
L=a+b+math.sqrt(c2)
h=(2*S)/a

print(S)
print(L)
print(h)


Measured memory_bytes: 5688
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,mid,l,f,i,ans=0,s=0,j,x;
    cin>>n;
    int a[n+4];
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(i=0; i<n-2; i++)
    {
        for(j=i+1; j<n-1; j++)
        {
            x=a[i]+a[j];
            f=0;
            l=n-1;

            while(f<=l)
            {
                int mid = (f+l)/2;

                if(a[mid]<x)
                {
                    ans = mid-j;
                    f= mid+1;
                }
                else if(a[mid]>=x)
                {
                    l= mid - 1;
                }
            }
            s=s+ans;
        }
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque


def nearlist(N, LIST):  # 隣接リスト
    NEAR = [{} for _ in range(N)]
    for a, b, c in LIST:
        NEAR[a - 1][b - 1] = c
        NEAR[b - 1][a - 1] = c
    return NEAR


def bfs(NEAR, S, N):  # 幅優先探索  # キュー
    DIST = [-1 for _ in range(N)]  # 前処理
    DIST[S] = 0
    que, frag = deque([S]), set([S])

    while que:
        q = que.popleft()
        for i, c in NEAR[q].items():  # 移動先の候補
            if i in frag:  # 処理済みか否か
                continue
            DIST[i] = DIST[q] + c
            que.append(i), frag.add(i)
    return DIST


n = int(input())
abc = [list(map(int, input().split())) for _ in range(n - 1)]
q, k = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(q)]

near = nearlist(n, abc)
dist = bfs(near, k - 1, n)
for x, y in xy:
    print(dist[x - 1] + dist[y - 1])


Measured memory_bytes: 165068
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			long[] as = new long[N];
			for(int i = 0; i < N; i++) {
				as[i] = sc.nextLong();
			}
			
			long[] prefix_as = new long[N + 1];
			for(int i = 0; i < N; i++) {
				prefix_as[i + 1] += prefix_as[i] + as[i];
			}
			
			long answer = Long.MAX_VALUE;

			for(int i = 0; i < N; i++) {
				long fst_part = prefix_as[i];
				long snd_part = prefix_as[N] - prefix_as[i];
				
				
				answer = Math.min(Math.abs(fst_part - snd_part), answer);
			}
			
			System.out.println(answer);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 54356
#include<stdio.h>

int main(){
  int n,num;
  long long int i,j;
  int p[1000001];

  num = 0;
  p[1] = 0;
  for(i = 2;i<=1000000;i++){
   for(j = 2;j*j<=i;j++){
     if(!(i%j))break;
   }
   if(j*j>i)num++;
   p[i] = num;
  }
  while(scanf("%d",&n)!=EOF){
    printf("%d\n",p[n]);
  }
}

Measured memory_bytes: 4176
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;

typedef long long ll;

const int INF = 1e8;

int main() {

  int q, n, d1, d2;

  int num[6];
  int a[101] = {};

  for(int i=0; i<6; ++i) {
    cin >> num[i];
    a[num[i]] = i;
  }

  int dice[6][6] = {{0, num[2], num[4], num[1], num[3], 0},
                    {num[3], 0, num[0], num[5], 0, num[2]},
                    {num[1], num[5], 0, 0, num[0], num[4]},
                    {num[4], num[0], 0, 0, num[5], num[1]},
                    {num[2], 0, num[5], num[0], 0, num[3]},
                    {0, num[3], num[1], num[4], num[2], 0}};

  cin >> q;

  while(q--) {
    cin >> d1 >> d2;

    n = dice[a[d1]][a[d2]];

    cout << n << endl;
  }

  return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 ll N;
  cin>>N;
  ll ans=0;
  for(ll i=1;i<=N;i++) {
ll A=N/i;
    ans+=i*A*(A+1)/2;
  }
  cout<<ans<<endl;
}
  
  

  
  
  
  
  
  
  
  
  
  
  
  
  

Measured memory_bytes: 3636
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main()
{
  int n;
  int i,j;
  double sum=0;
  double ans=0;

  scanf("%d",&n);

  int A[n][2];

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

  for(i=0;i<n-1;i++)
  {
    for(j=i+1;j<n;j++)
    {
      double dis;
      dis=sqrt((A[i][0]-A[j][0])*(A[i][0]-A[j][0])+(A[i][1]-A[j][1])*(A[i][1]-A[j][1]));
      sum=sum+dis;
    }
  }

  ans=sum*2/n;

  printf("%.10f",ans);

  return 0;
}


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

int calcdigit(ll a){
    int d = 0;
    while(a > 0){
        a /= 10;
        d++;
    }
    return d;
}

bool checkdigit(ll a, ll b){
    // cout << a << " " << calcdigit(a) << " " << b << " " << calcdigit(b) << endl;
    // int dab = calcdigit(a) + calcdigit(b);
    if(calcdigit(a) + calcdigit(b) >= 20 && a*b != (ll)1e18) {
        return false;
    }
    if(calcdigit(a*b) >= 19){
        return false;
    }
    if(calcdigit(max(a,b)/100 * min(a,b)) >= 17){
        return false;
    }
    return true;
}

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);
    ll res = 1;
    rep(i,n){
        if(a.at(i) == 0) {
            res = 0;
            break;
        }
        if(res > (max_val/a.at(i))){
            res = -1;
        }
        if(res > 0){
            res = res * a.at(i);
        }
    }
    cout << res << endl;
    return 0;
}

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

int main() {
	char c;
	cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
		cout << "vowel" << endl;
	else
		cout << "consonant" << endl;
	return 0;
}

Measured memory_bytes: 256
import heapq

N, M = map(int, input().split())
A = []
S = list(map(int, input().split()))

for s in S:
	heapq.heappush(A, s * -1)
	
for _ in range(M):
	tmp = heapq.heappop(A)
	if tmp > 0:
		tmp //= 2
	else:
		tmp *= -1
		tmp //= 2
		tmp *= -1
	heapq.heappush(A, tmp)
	
print(sum(A) * -1)

Measured memory_bytes: 64920
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  string S;
  cin>>S;
  for(ll i=0;i<10;i++) {
if(i==3) {
cout<<'8';
}
    else{
cout<<S[i];
    }
  }
  
  cout<<endl;
}

Measured memory_bytes: 3532
//#define _GLIBCXX_DEB // Iterator safety; out-of-bounds access for Containers, etc.
//#pragma GCC optimize "trapv" // abort() on (signed) integer overflow.
#include <bits/stdc++.h>

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

#define ll long long int
#define mod 1000000007
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.1415926535897932384626
#define INF 1000000000
#define bits(n) __builtin_popcount(n)

int a[100001][3];
int f[100001][3];

void solve()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>a[i][j];
        }
    }
    f[0][0]=a[0][0];
    f[0][1] = a[0][1];
    f[0][2] = a[0][2];

    for(int day=1;day<n;day++)
    {
        f[day][0]=a[day][0]+max(f[day-1][1],f[day-1][2]);
        f[day][1] = a[day][1] + max(f[day - 1][0], f[day - 1][2]);
        f[day][2] = a[day][2] + max(f[day - 1][0], f[day - 1][1]);
    }
    int res1=f[n-1][0];
    int res2=f[n-1][1];
    int res3=f[n-1][2];
    cout<<max(max(res1,res2),res3);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input1.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
#endif

    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 5964
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;
inline int toInt(string s){int v;istringstream i(s);i>>v;return v;}
template<class T> inline string toString(T x){ostringstream o;o<<x;return o.str();}
template<class T> void pv(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}
const int INF = 1000000000;
const double PI = acos(-1.0), EPS = 1e-10;

int main() {
	for(int N; cin >> N, N;) {
		vector<pair<double, int> > v;
		for(int i = 0; i < N; i++) {
			int num, h, w;
			cin >> num >> h >> w;
			v.push_back(mp(fabs(22.0 - w / (h * h / 10000.0)), num));
		}

#if 0
		cerr << "debug" << endl;

		for(int i = 0, end = v.size(); i != end; ++i)
			cerr << v[i].first << endl;
#endif

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

		cout << v.at(0).second << endl;
	}

	return 0;
}

Measured memory_bytes: 0
using System;
using static System.Console;
using static System.Int32;
using static System.Math;
using System.Linq;
using System.Collections.Generic;

class Solution
{
    static void Main()
    {
    lb:
        var sp = ReadLine().Split();
        int n = Parse(sp[0]);
        var m = Parse(sp[1]);
        var keys = new Dictionary<int, int>();
        keys[0] = 0;
        for (int i = 0; i < m; ++i)
        {
            var nedan = Parse(ReadLine().Split()[0]);
            int hako = 0;
            foreach (var c in ReadLine().Split().Select(Parse))
            {
                hako |= (1 << (c - 1)); 
            }
            foreach(var pair in keys.ToArray())
            {
                var kk = pair.Key | hako;
                var val = pair.Value + nedan;
                int val2;
                if (!keys.TryGetValue(kk, out val2) || val < val2) keys[kk] = val;
            }
        }
        int result;
        WriteLine(keys.TryGetValue((1 << n) - 1, out result) ? result : -1);
    }
}


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

int main(){
  cin>>N>>X;
  ll ans=N;
  ll h=N-X,w=X;
  while(1){
    if(h<w)swap(h,w);
    if(w==0)break;
    ll d=h/w;
    ans+=d*w*2;
    
    if(h%w==0)ans-=w;
    
    if(w==1)break;
    
    h=h%w;
    w=w;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
 
public class Hello{
    static public int mod = 1000000007;
    public static void Main(){
        long[] num = longa();
        long ans = num[0]*num[1]/2;
        long aaa = num[0]*num[1];
        if(num[0] == 1 || num[1]==1){
            WriteLine(1);
        }else{
            WriteLine(aaa-ans);
        }
        
        
    

        
        
        
        
    }
    static int ncr(int n,int r){r = Min(r,n-r);long nn = 1;for(int i=n-r+1;i<=n;i++){nn = nn*i%mod;}long rr = 1;for(int i=1;i<=r;i++){rr = rr*i%mod;}rr = square((int)rr,mod-2);nn = nn * rr %mod;return (int)nn;}
    // a^b mod
    static int square(int a,int b){string binary = Convert.ToString(b,2);int bileng = binary.Length;long a_power = a;long value = 1;for(int i=bileng-1;i>=0;i--){if(binary[i] == '1'){value = value*a_power%mod;}a_power = a_power*a_power%mod;}return (int)value;}
    //static int square2(long a,long b,long m){var list = new List<int>();int temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp < b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b > 0){if(temp <= b){b -= temp;ret = ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;}
    //各種読取
    static string rstr(){ return ReadLine(); }
    static int rint(){ return int.Parse(ReadLine()); }
    static long rlong(){ return long.Parse(ReadLine()); }
    static string[] stra(){ return ReadLine().Split(' '); }
    static int[] inta(){ string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for(int countup_i=0;countup_i<read_str_array.Length;countup_i++){ return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; }
    static int[,] inta2(int num_array,int in_array){ int[,] int_array2 = new int[num_array,in_array]; for(int i=0;i<num_array;i++){ int[] temp_array = inta(); for(int j=0;j<in_array;j++){ int_array2[i,j] = temp_array[j]; } } return int_array2; }
    static long[] longa(){ string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for(long countup_i=0;countup_i<read_str_array.Length;countup_i++){ return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; }
    static double[] doublea(){ string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for(long countup_i=0;countup_i<read_str_array.Length;countup_i++){ return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; }
    // -----------------------------
    static long divideup(long divided,long divid){ long temp_divide = divided/divid; if(divided % divid > 0){ temp_divide++; } return temp_divide; }
    static long GCD(long a,long b){ if(a < b){ long temp = a; a = b; b = temp; } if(a % b == 0){ return b; } else{ long temp = b; b = a%b; a = temp; return GCD(a,b); } }
    static long LCM(long a,long b){ return a * b / GCD(a,b); }
}



Measured memory_bytes: 13140
#include<stdio.h>
#include<string.h>
char s[200000];
int main()
{
    int i,j,k,l,m,n;
	scanf("%s",s);
	int str=strlen(s);
	for(i=0;i<str;i++)
	if(s[i]=='A')
	break;
	for(j=str;j>=0;j--)
	if(s[j]=='Z')
	break;
	printf("%d",j-i+1); 
	return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int len = S.length();
    int cnt = 0;
    rep(i, len / 2) {
        if (S[i] != S[len - 1 - i]) cnt++;
    }
    cout << cnt << endl;

    return 0;
}


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

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 1e9 + 7;

struct ad_set
{
	int tag;
	deque<int> que;
	
	void subt(int x)
	{
		tag += x;
	}
	
	void push_front(int x)
	{
		que.push_front(x + tag);
	}
	void push_back(int x)
	{
		que.push_back(x + tag);
	}
	int back()
	{
		return que.back() - tag;
	}
	void pop_back()
	{
		que.pop_back();
	}
	int size()
	{
		return que.size();
	}
}tre;

int n;
char s[1000005], t[1000005];
int term[1000005], dest[1000005];
vector<int> occ[26];

int main()
{
	scanf("%d%s%s", &n, s, t);
	rep(i, n) {
		s[i] -= 'a';
		t[i] -= 'a';
	}
	rep(i, n) occ[s[i]].push_back(i);
	int maxt = n - 1;
	for(int i = n - 1; i >= 0; i --) {
		maxt = min(maxt, i);
		vector<int>::iterator pos = upper_bound(occ[t[i]].begin(), occ[t[i]].end(), maxt);
		if(pos == occ[t[i]].begin()) {
			printf("-1\n");
			return 0;
		}
		else maxt = term[i] = *(-- pos);
	}
	
	rep(i, n) dest[i] = -1;
	term[n] = -1;
	for(int i = n - 1; i >= 0; i --)
	if(term[i] != term[i + 1]) dest[term[i]] = i;
	
	int ans = 0;
	for(int i = n - 1; i >= 0; i --) {
		if(dest[i] == -1) continue;
		tre.subt(1);
		tre.push_front(i);
		while(tre.size() > 0 && tre.back() >= dest[i]) tre.pop_back();
		tre.push_back(dest[i]);
		ans = max(ans, tre.size());
	}
	printf("%d\n", ans - 1);
	return 0;
}

Measured memory_bytes: 18440
N, K, Q = map(int, input().split())

A = [K]*N
C = [0]*N

for r in range(Q):
    correct = int(input())
    C[correct-1] = C[correct-1] + 1

for i in range(N):
    A[i] = A[i] - Q + C[i]
    if A[i] > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 8520
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    int ret = n;
    for (int i = 0; i <= n; i++) {
        int a = 0, b = 0, c = i, d = n - i;
        while (c) {
            a += c % 6;
            c /= 6;
        }
        while (d) {
            b += d % 9;
            d /= 9;
        }
        ret = std::min(ret, a + b);
    }
    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

public class Main {
	static String s = "";
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			s = br.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		HashMap<Integer, String> map = new HashMap<>();
		
		System.out.println(search(map,"", 0, 1));
}
	static int search(HashMap<Integer, String> map, String prev, int begin, int len) {
		if(begin+len > s.length())return map.size();
		String sub = s.substring(begin, begin+len);
		if(sub.equals(prev)) {
			return search(map,prev, begin, len+1);
		}else {
			map.put(begin, sub);
			return search(map, sub,begin+len, 1);
		}
		
	}
}


Measured memory_bytes: 97252
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

void call(int n)
{
  int i = 1;
  int x;

  do {
    x = i;
    if (x % 3 == 0) {
      printf(" %d", i);
    }
    else {
      do {
	if (x % 10 == 3) {
	  printf(" %d", i);
	  x = 0;
	}
	else x /= 10;
      } while (x);
    }
  } while (++i <= n);
  putchar('\n');
}

int main()
{
  int x;

  scanf("%d", &x);
  call(x);
  return 0;
}




Measured memory_bytes: 2104
#include<iostream>
using namespace std;
int main(){
   int s1s2s3 ;
   cin >> s1s2s3 ;
   int d = s1s2s3 % 10 ;
   int f = ( s1s2s3 - d ) %100 ;
   int g = ( s1s2s3 - d - f ) /100 ;
   int h = d + ( f / 10 ) + g;
   cout << h << endl ;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<string> a(n), b(m);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    string ans = "No";
    for (int sw = 0; sw <= n - m; sw++) {
        for (int sh = 0; sh <= n - m; sh++) {
            bool ng = false;
            for (int w = 0; w < m; w++) {
                for (int h = 0; h < m; h++) {
                    if (a[sw + w][sh + h] != b[w][h]) {
                        ng = true;
                        break;
                    }
                    if (ng) break;
                    if (w == m - 1) ans = "Yes";
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)


using namespace std;
using ll = long long;

void solve() {
    string s;
    cin >> s;
    if (s[0] == '7' || s[1] == '7' || s[2] == '7') {
        cout << "Yes\n";
        return;
    }
    cout << "No\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);

    solve();
    return 0;
}


Measured memory_bytes: 3648
n, m = list(map(int, input().split()))
MOD = 1000000007

dp = [0 for i in range(n+5)]
dp[0] = 1
a = set()
for i in range(m):
  t = int(input())
  a.add(t)

for i in range(n):
  if i+2 not in a:
    dp[i+2] = (dp[i+2]+dp[i])%MOD
  if i+1 not in a:
    dp[i+1] = (dp[i+1]+dp[i])%MOD

print(dp[n])

Measured memory_bytes: 51488
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int n;
    cin>>n;
    int ans=1;
    while(ans<=n){
        ans<<=1;
    }
    cout<<(ans>>1)<<endl;
    return 0;
}

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

int countBlacks(int i, int j);
  

int n, m, k;
int main()
{
  cin >> n >> m >> k;
  
  vector<int> availableKs;
  for(int i=0; i<=n; ++i){    //行 
    for(int j=0; j<=m; ++j){    //列
      availableKs.push_back(countBlacks(i, j));
    }
  }
  
  if(find(begin(availableKs), end(availableKs), k) != end(availableKs))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
int countBlacks(int i, int j){
  int result = 0;
  for(int y=0; y<n; ++y){
    if(y < i){ //y行目は反転している
      result += (m-j);
    }else{    //y行目は反転していない
      result += j;
    }
  }
  return result;
}

Measured memory_bytes: 6256
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>

using namespace std;
int main() {
    string s;
    cin >> s;
    int ans = 0;
    if (s[0] == s[1]) {
        ans++;
    }
    if (s[0] == s[2]) {
        ans++;
    }
    if (s[0] == s[3]) {
        ans++;
    }
    if (s[1] == s[2]) {
        ans++;
    }
    if (s[1] == s[3]) {
        ans++;
    }
    if (s[2] == s[3]) {
        ans++;
    }
    if (ans == 2) {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }


    return 0;
}

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



bool is_prime(long long num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	long long sqrtNum = sqrt(num);
	for (long long i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

vector<long long> divisor(long long n) {
	vector< long long > ret;
	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}


int main() {

	long long N;
	cin >> N;

	if (is_prime(N)){
		cout << N-1 << endl;
		return 0;
	}

	vector<long long> ret = divisor(N);
	long long index;
	//cout << ret.size() << endl;
	if (ret.size() % 2 == 0) {
		index = ((long long)ret.size() / 2) - 1;
	}
	else {
		index = ((long long)ret.size() / 2);
	}

	long long i = ret[index];
	long long j = N / i;
	/*
	for (int i = 0; i < ret.size(); i++)
	{
		cout << ret[i] << endl;
	}*/
	
	cout << (i - 1) + (j - 1) << endl;
	
	return 0;
}

Measured memory_bytes: 384
from sys import stdin

if __name__ == '__main__':
    s = stdin.readline().rstrip()
    flag = 1
    a = s[0]
    if s[0] == s[1]:
        flag = 0
    elif s[1] == s[2]:
        flag = 0
    elif s[2] == s[3]:
        flag = 0
    else:
        pass
    
    if flag == 1:
        print("Good")
    else:
        print("Bad")


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>
#include<deque>
#include<fstream>
#include<random>
 
#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
#define First first
#define Second second.first
#define Third second.second
#define Sort(X) sort(X.begin(), X.end())
#define RSort(X, T) sort(X.begin(), X.end(), greater<T>())
//#define MOD 998244353
#define MAX 100000
 
typedef long long int ll;
typedef unsigned long long int ull;
 
using namespace std;
 
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; }
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll N;
	cin >> N;

	vl B(N - 1);
 
	rep(i, N-1) {
		cin >> B[i];
	}

	ll out = B[0];
	rep(i, N-2) {
		out += min(B[i], B[i + 1]);
	}
	out += B[N - 2];

	cout << out << endl;


	return 0;
}

Measured memory_bytes: 888
n,m=map(int,input().split())
sa = []

lst=sorted(list(map(int,input().split())))[::-1]
for i in range(len(lst)-1):
    sa.append(int(abs(lst[i]-lst[i+1])))
sa = sorted(sa)[::-1]
print(sum(sa[n-1:]))

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

int main(void)
{
	int n ;
	scanf("%d",&n) ;
	int thousand = 0  , five = 0  ; 
	while( n >= 500 )
	{
		n = n - 500 ;
		thousand = thousand + 1000 ;
	}
	while( n >= 5)
	{
		n = n - 5 ;
		five = five + 5 ;
	}
	
	int ans ;
	ans = thousand +five ;
	
	printf("%d\n",ans) ;
	
	return 0 ;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio (false);
	cout << fixed;
	cout.precision(10);
	if(fopen("joke.in", "r")){
		freopen ("joke.in","r",stdin);
		freopen ("joke.out","w",stdout);
	}

	int N, W;
	cin >> N >> W;

	vector<long long> weight(N + 1), value(N + 1);

	for(int i = 1; i <= N; ++i){
		cin >> weight[i] >> value[i];
	}

	vector<vector<long long>> dp(N + 1, vector<long long>(W + 1, 0));
	
	dp[1][weight[1]] = value[1];
	for(int w = 2; w <= W; ++w){
		dp[1][w] = max(dp[1][w], dp[1][w - 1]); 
	}

	for(int i = 2; i <= N; ++i){
		for(int w = 1; w <= W; ++w){
			dp[i][w] = max(dp[i][w], dp[i - 1][w]);
			if(w - weight[i] < 1) continue;
			dp[i][w] = max(dp[i][w], dp[i - 1][w - weight[i]] + value[i]); 
		}
	}

	cout << dp[N][W];
    return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
	// your code goes here
	int n;
	cin>>n;
	int a[n];
	rep(i,n)
	cin>>a[i];
	int dp[n];
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(int i=2;i<n;i++)
	{
	    dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
	}
	cout<<dp[n-1];
	return 0;
}



Measured memory_bytes: 1024
/**********************
 * Author: Cloud_     *
 * Date:   06.07.2020 * 
 * Time:   15.45.10   *
 *                    *
***********************/
#include <bits/stdc++.h>
using namespace std;

#define gap " "
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ok cout<<"ok"<<endl
#define dbg(x) cout<<(#x)<<" is "<<x<<endl
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}

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

const int N=100009;
map<string,int> mpp;
int main()
{
  //fastio; 
  string s;
  int n,ans,i;
  cin>>n;
  for(i=0; i<n; i++)
  {
  	 cin>>s;
  	 mpp[s]++;
  }
  cout<<"AC x "<<mpp["AC"]<<'\n';
  cout<<"WA x "<<mpp["WA"]<<'\n';
  cout<<"TLE x "<<mpp["TLE"]<<'\n';
  cout<<"RE x "<<mpp["RE"]<<'\n';
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,A=0;
  string S;
  cin >> N >> K >> S;
  int count=1;
  for(int i = 1; i < N; i++){
    if(S[i] != S[i-1]){
      count ++;
    }
  }
  cout <<N+min(-1,-count+2*K)<<endl;
}

Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		//C
		int N = sc.nextInt();
		int X = sc.nextInt();
		ArrayList<Integer> x = new ArrayList<>();
		int[] dis = new int[N];
		int D  = 1;

		if(N == 1){
			System.out.println(Math.abs(X-sc.nextInt()));
			return;
		}
		x.add(X);
		for(int i = 0 ; i < N ; i++){
			x.add(sc.nextInt());
		}
		Collections.sort(x);

		for(int i = 0 ; i < N ; i++){
			dis[i] = x.get(i+1) - x.get(i);
			//System.out.println(i+":"+dis[i]);
		}

		D = dis[0];
		for(int distance : dis){
			//System.out.println(distance);
			D = gcd(D,distance);
		}
		System.out.println(D);
	}

	public static int gcd(int p,int q){
		int tmp;
		int a;
		int b;
		if(p < q){
			a = q;
			b = p;
		}else{
			a = p;
			b = q;
		}
		//System.out.println(a+":"+b+"");
		while((tmp = a % b) != 0){
			a = b;
			b = tmp;
		}
		return b;
	}
}

Measured memory_bytes: 62724
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  map<string, map<int, int, greater<int>>> res;
  rep(i, N) {
    string S; cin >> S;
    int P; cin >> P;
    res[S][P] = i+1;
  }

  for(auto city: res) for (auto x: city.second) cout << x.second << endl;
  return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

int main() {
    int k, x;
    cin >> k >> x;
    if (500 * k >= x)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256