akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cassert>

using namespace std;

const int N = 10000;

int ten[6] = {1, 10, 100, 1000, 10000, 100000};

int getDigits(int a){
  if(a == 0) return 1;
  int res = 0;
  while(a != 0){
    res++;
    a /= 10;
  }
  return res;
}

int calc(int a, int b){
  int d = getDigits(b);
  return a * ten[d] + b;
}

main(){
  int n;
  int data[N+1];
  fill(data, data+N+1, 0);
  cin >> n;
  vector<int> vec;
  for(int i=0;i<n;i++){
    int in;
    cin >> in;
    //assert(in <= ten[4]);
    //assert(data[in] == 0);
    data[in]++;
    //vec.push_back(in);
  }
  int cnt = 0;
  for(int i=0;cnt<n&&cnt<4&&i<=N;i++){
    for(int j=0;cnt<n&&cnt<4&&j<data[i];j++){
      vec.push_back(i); cnt++;
    }
    }
  //for(int i=0;i<vec.size();i++) cout << vec[i] << ' '; cout << endl;
  vector<int> ans;
  int m[3] = {200000000, 200000000, 200000000};
  for(int i=0;i<vec.size();i++){
    for(int j=0;j<vec.size();j++){
      if(i == j) continue;
      ans.push_back(calc(vec[i], vec[j]));
      /*int t = calc(vec[i], vec[j]);
      if(t < m[0]){ m[2] = m[1]; m[1] = m[0]; m[0] = t; }
      else if(t < m[1]){ m[2] = m[1]; m[1] = t; }
      else if(t < m[2]){ m[2] = t; }*/
    }
  }
  //for(int i=0;i<ans.size();i++) cout << ans[i] << ' '; cout << endl;
  sort(ans.begin(), ans.end());
  cout << ans[2] << endl;
  //cout << m[2] << endl;
}

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

#define M 200005
#define MAXX 999999999999999
#define PI 3.14159265358979323846
#define ep emplace_back
#define mk make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> PII;
typedef pair<lli,lli> PLL;

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

//   freopen("input.txt","r",stdin);

   string s;
   cin>>s;
   
   int ans = 0;
   int cnt = 0;
   for(int i=0;i<3;i++)
   {
      if(s[i]=='S')
      {
         ans = max(ans,cnt);
         cnt = 0;
      }
      else
         cnt++;
   }
   
   ans = max(ans,cnt);
   cout<<ans<<"\n";
   
}


Measured memory_bytes: 3644
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
n = ii()
sm = set()
sa = set()
sr = set()
sc = set()
sh = set()

for _ in range(n):
    tmp = input()
    d = tmp[0]
    if d == 'M':
        sm.add(tmp)
    elif d == 'A':
        sa.add(tmp)
    elif d == 'R':
        sr.add(tmp)
    elif d == 'C':
        sc.add(tmp)
    elif d == 'H':
        sh.add(tmp)

d = {}
d['m'] = len(sm)
d['a'] = len(sa)
d['r'] = len(sr)
d['c'] = len(sc)
d['h'] = len(sh)
A = 'march'
ans = 0
for i in range(1<<5):
    output = []
    for j in range(5):
        if ((i>>j)&1)==1:
            output.append(A[j])
    if len(output) == 3:
        ans += d[output[0]]*d[output[1]]*d[output[2]]
print(ans)

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

#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define FOR(i,l,r) for(long long i=l; i<r; i++)
#define FOR_REV(i,r,l) for(long long i=r; i>=l; i--)
#define pb push_back
#define mp make_pair


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

    ll a[200008];
    map <ll, ll> cnt;
    
    FOR (i,0,n)
    {
        cin>>a[i];
        cnt[a[i]]++;
    }

    map <ll, ll> :: iterator it;
    ll sum = 0;

    for (it=cnt.begin(); it!= cnt.end(); it++)
    {
        if (it->second >= 2)
        {
            ll x = it->second;
            sum += x*(x-1)/2;
        }
    }

    for (ll i=0; i<n; i++)
    {
        ll ans = sum;
        ll x = cnt[a[i]];
        ans -= x*(x-1)/2;
        x--;
        if (x >= 2)
        {
            ans += x*(x-1)/2;
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 11008
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    int n,m;

    cin >> n >> m;

    int A[n][m];
    int b[m][1];
    int c[n][1];

    int i,j;

    for(i=0;i<n;i++){
        c[i][0] = 0;
    }

    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            cin >> A[i][j];
        }
    }

    for(i=0;i<m;i++){
        cin >> b[i][0];
    }    

    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            c[i][0] += A[i][j] * b[j][0];
        }
    }
        
    for(i=0;i<n;i++){
        cout << c[i][0] << endl;
    }

    return 0;
}


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

int main() {
	int loopCount;
	cin >> loopCount;

	int exP = 0, exW = 0, exG = 0, exY = 0;

	for (int i = 0; i < loopCount; i++) {
		string nowArare = "";
		cin >> nowArare;

		if (nowArare == "P") {
			exP = 1;
		}
		else if (nowArare == "W") {
			exW = 1;
		}
		else if (nowArare == "G") {
			exG = 1;
		}
		else if (nowArare == "Y") {
			exY = 1;
		}

	}

	if (exP + exW + exG + exY == 3) {
		cout << "Three" << endl;
	}
	else {
		cout << "Four" << endl;
	}

}


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

int main(){
  int n;
  int k;
  scanf("%d %d",&n,&k);
  char s[n];
  scanf("%s",s);
  for(int i=0;i<n;i++){
    if(i+1==k){
      s[i]=tolower(s[i]);
    }
    printf("%c",s[i]);
  }
  return 0;
}

Measured memory_bytes: 128
n=int(input())
l=list(map(str,input()))
count=0
lis=[0]
for i in range(n):
    if  l[i]=='D':
        lis.append(count-1)
        count-=1
    else:
        lis.append(count+1)
        count+=1
print(max(lis))

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
const int N=3005,Mod=1e9+7,iM=Mod+1>>1;
int n,q,a[N],f[N][N],t[N][N],ans,p=1;
#define mul(x,y) (1ll*(x)*(y)%Mod)
inline int add(int x, int y)
{	return (x+y>=Mod?x+y-Mod:x+y);
}
int main()
{
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j) f[i][j]=(a[i]>a[j]);
	while(q--)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		if(x>y) swap(x,y);
		if(x==y) continue;
		t[x][y]=mul(iM,add(f[x][y],f[y][x]));
		for(int i=1;i<=n;++i) if(i!=x&&i!=y)
			t[x][i]=mul(iM,add(f[x][i],f[y][i])),
			t[i][x]=mul(iM,add(f[i][x],f[i][y])),
			t[y][i]=mul(iM,add(f[y][i],f[x][i])),
			t[i][y]=mul(iM,add(f[i][y],f[i][x]));
		f[x][y]=f[y][x]=t[x][y];
		for(int i=1;i<=n;++i) if(i!=x&&i!=y)
			f[x][i]=t[x][i],f[i][x]=t[i][x],f[y][i]=t[y][i],f[i][y]=t[i][y];
		p=mul(2,p);
	}
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j) ans=add(ans,f[i][j]);
	printf("%d\n",mul(ans,p));
}


Measured memory_bytes: 70784
d,g = map(int,input().split())
li = [list(map(int,input().split())) for _ in range(d)]

ans = 10**10

def score(count,sum,q,s):
    global ans
    if count == d+1:
        if s == 0:
            if g <= sum:
                ans = min(ans,sum)
        else:
            for i in range(li[s-1][0]+1):
                a = sum
                q2 = q
                if i == li[s-1][0]:
                    a += s*100*i + li[s-1][1]
                    q2 += i
                else:
                    a += s*100*i
                    q2 += i
                if g <= a:
                    ans = min(ans,q2)
    else:
        score(count+1,sum,q,count)
        score(count+1,sum+count*100*li[count-1][0]+li[count-1][1],q+li[count-1][0],s)

score(1,0,0,0)

print(ans)


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define ll long long

using namespace std;

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

  vector<int> A(N), X(M), Y(M);

  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }

  for(int i = 0; i < M; i++) {
    cin >> X[i] >> Y[i];
  }

  int unoccupied = 0;

  unordered_map<int, int> um;

  vector<int> occupied(N);

  for(int i = 0; i < N; i++) {
    um[A[i]] += 1;
  }

  for(auto p: um) {
    for(int k = 0; k < p.second; k++) {
      if(p.first - 1 - k >= 0)
        occupied[p.first - 1 - k] += 1;
    }
  }

  for(int i = 0; i < N; i++) {
    if(occupied[i] == 0)
      unoccupied += 1;
  }

  for(int i = 0; i < M; i++) {


    int from = A[X[i] - 1];
    int to = Y[i];

    if(from == to) {
      cout << unoccupied << endl;
      continue;
    }

    if(from - um[from] >= 0) {
      occupied[from - um[from]] -= 1;
      if(occupied[from - um[from]] == 0) {
        unoccupied += 1;
      }
    }

    if(to - (um[to] + 1) >= 0) {
      occupied[to - (um[to] + 1)] += 1;
      if(occupied[to - (um[to] + 1)] == 1) {
        unoccupied -= 1;
      }
    }

    um[from] -= 1;
    um[to] += 1;

    A[X[i] - 1] = Y[i];

    cout << unoccupied << endl;

  }

}


Measured memory_bytes: 12744
#アルゴリズム関数-サイコロを回転させる
def dice_rotation(list1, str1):
    if str1 == "S":
        list1[0],list1[1],list1[4],list1[5] = list1[4],list1[0],list1[5],list1[1]
    elif str1 == "E":
        list1[0],list1[2],list1[3],list1[5] = list1[3],list1[0],list1[5],list1[2]
    elif str1 == "N":
        list1[0],list1[1],list1[4],list1[5] = list1[1],list1[5],list1[0],list1[4]
    elif str1 == "W":
        list1[0],list1[2],list1[3],list1[5] = list1[2],list1[5],list1[0],list1[3]
    return list1

#アルゴリズム関数-上面・前面の番号を指定番号へサイコロを回転させる
def dice_find(list1, int1, int2):
    position_numnber = list1.index(int2)
    if position_numnber == 0:
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 2:
        list1 = dice_rotation(list1, "W")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 3:
        list1 = dice_rotation(list1, "E")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 4:
        list1 = dice_rotation(list1, "S")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 5:
        list1 = dice_rotation(list1, "N")
    position_numnber = list1.index(int1)
    if position_numnber == 2:
        list1 = dice_rotation(list1, "W")
    elif position_numnber == 3:
        list1 = dice_rotation(list1, "E")
    elif position_numnber == 5:
        list1 = dice_rotation(list1, "W")
        list1 = dice_rotation(list1, "W")
    return list1

#インプットdataの格納
input_number = list(map(int, input().split()))
check_number = list(map(int, input().split()))

#処理の実行
check_number = dice_find(check_number, input_number[0], input_number[1])

#結果表示
if input_number == check_number:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 5608
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s,t=STRM()
    a,b=INTM()
    u=STR()
    if s==u:
        print(a-1,b)
    else:
        print(a,b-1)
if __name__ == '__main__':
    do()

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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s)
{
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}
template <class T>
inline string toString(T x)
{
	ostringstream sout;
	sout << x;
	return sout.str();
}

//math
//-------------------------------------------
template <class T>
inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

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

//repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
					  << " " << __FILE__ << endl;

int main(void)
{
	string s;
	cin >> s;
	s[3] = '8';
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>
#include <cstring>


int main() {
    int n; std::cin >> n;
    std::string s; std::cin >> s;
    s = '@' + s;
    bool left[30003][10] = {}, right[30003][10] = {};
    for (int i = 1; i <= n; i++) {
        left[i][s[i] - '0'] = true;
        for (int j = 0; j < 10; j++) {
            left[i + 1][j] = left[i][j];
        }
    }
    for (int i = n; i > 0; i--) {
        right[i][s[i] - '0'] = true;
        for (int j = 0; j < 10; j++) {
            right[i - 1][j] = right[i][j];
        }
    }
    std::set<int> st;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 10; j++) {
            if (!left[i - 1][j]) continue;
            for (int k = 0; k < 10; k++) {
                if (!right[i + 1][k]) continue;
                st.insert(100 * j + 10 * (s[i] - '0') + k);
            }
        }
    }
    std::cout << st.size() << std::endl;
    return 0;
}

Measured memory_bytes: 1024
import sys

readline = sys.stdin.readline

def main():
    N, M = map(int, readline().split())
    check = [0]*N
    pena = [0]*N
    for _ in range(M):
        p, S = readline().split()
        p = int(p)-1
        if S == 'AC':
            check[p] = 1
        else:
            pena[p] += (not check[p] == 1)*1
    
    ans_ac = sum(check)
    ans_pena = 0
    for i in range(N):
        ans_pena += pena[i] * (check[i] >= 1)
    print(ans_ac, ans_pena)

if __name__ == "__main__":
    main()


Measured memory_bytes: 4596
fun main(x:Array<String>) {
  val (n,m) = readLine()!!.split(" ").map(String::toInt)
  val a = readLine()!!.split(" ").map(String::toInt).toMutableList()
  var l : MutableList<List<Int>> = mutableListOf()
  for (i in 0..m-1) {
    l.add(readLine()!!.split(" ").map(String::toInt))
  }
  a.sort()
  l.sortBy {-it[1]}
  var ans = 0L
  var idx = 0
  run loop@ {
    l.forEach {
      for ( i in 0..it[0]-1) {
	    if (it[1] <= a[idx]) return@loop
        a[idx] = it[1]
        idx++
        if (idx >= a.size) return@loop
      }
    }
  }
  
  a.forEach {ans += it}
  println(ans)
  
}

Measured memory_bytes: 87492
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    string s;
    cin >> s;

    int L = s.size();

    if(s=="keyence"){
        p_yes();
        return 0;
    }

    // l, r取り除く範囲
    FOR(l, 0, L){
        FOR(r, l, L){
            string t = s.substr(0, l) + s.substr(r+1);
            if(t=="keyence"){
                p_yes();
                return 0;
            }
        }
    }
    p_no();
    return 0;
}

Measured memory_bytes: 256
// Charan Sriramula
 
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;
 
const ll lg=22;
const ll N=2e5+5;
const ll M=5e8;
const ll INF=1e18;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;
 
#define is(n) scanf("%d",&n)
#define io(n) printf("%d\n",n)
#define ls(n) scanf("%lld",&n)
#define lo(n) printf("%lld\n",n)
 
#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
 
inline ll mul(ll a, ll b, ll p){ return (a * 1ll * b) % p; }
inline ll sub(ll a, ll b, ll p){ ll c = a - b; if(c < 0) c += p; return c; }
inline ll add(ll a, ll b, ll p){ ll c = a + b; if(c > p) c -= p; return c; }
 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

int main()
{
    ll n;
    cin>>n;
    ll a[n+1],ans[n+1],sum=0;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i&1){sum+=a[i];}
        else{sum-=a[i];}
    }
    ans[1]=sum;
    for(ll i=2;i<=n;i++)
    {
        ans[i]=(2*a[i-1])-ans[i-1];
    }
    for(ll i=1;i<=n;i++){cout<<ans[i]<<" ";}
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
	cout << fixed << setprecision(10);
	ll d,n;
	cin >> d >> n;
	if(d==0){
		if(n<=99) cout << n << endl;
		else cout << 101 << endl;
	}else if(d==1){
		if(n<=99) cout << 100*n << endl;
		else cout << 10100 << endl;
	}else{
		if(n<=99) cout << 10000*n << endl;
		else cout << 1010000 << endl;
	}
	return 0;
}

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

const lli mod = 1e9+7;

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< mod >;

lli n;

int main(void){
    cin >> n;
    vector<modint> a(n);
    rep(i, n) cin >> a[i];
    modint ans = 0;
    rep(i, n) ans+=a[i];
    ans*=ans;
    rep(i, n) ans-=a[i]*a[i];
    ans/=2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3996
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

class LowLink():
    def __init__(self,G):
        self.N = len(G)
        self.G = G
        self.low = [-1] * self.N
        self.ord = [-1] * self.N
    
    def _dfs(self,v,time,p = -1):
        self.ord[v] = self.low[v] = time
        time += 1

        isArticulation = False
        cnt = 0
        for e in self.G[v]:
            if self.low[e] < 0:
                cnt += 1
                self._dfs(e,time,v)
                self.low[v] = min(self.low[v],self.low[e])
                if p != -1 and self.ord[v] <= self.low[e]:
                    isArticulation = True
                if self.ord[v] < self.low[e]:
                    if v < e:
                        self.bridge.append((v,e))
                    else:
                        self.bridge.append((e,v))
            elif e != p:
                self.low[v] = min(self.low[v],self.ord[e])
        
        if p == -1 and cnt >= 2:
            isArticulation = True
        if isArticulation:
            self.articulation.append(v) 

    def build(self):
        self.articulation = []
        self.bridge = []
        self._dfs(0,0)
    

def main():
    V,E = map(int,input().split())
    G = [[] for _ in range(V)]
    for _ in range(E):
        a,b = map(int,input().split())
        G[a].append(b)
        G[b].append(a)
    
    lowlink = LowLink(G)
    lowlink.build()
    ans = lowlink.bridge
    ans.sort()
    if ans:
        for t in ans:
            print(*t)
if __name__ == '__main__':
    main()


Measured memory_bytes: 21292
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>

int main(){
  long long N,H;
  std::cin >> N >> H;

  std::vector<long long> b_arr(N);
  long long max_a = 0;

  for(int i = 0; i < N; i++){
    long long a;
    std::cin >> a >> b_arr[i];
    max_a = std::max(max_a, a);
  }

  std::sort(b_arr.rbegin(), b_arr.rend());

  long long ncount = 0;
  for(auto&& b: b_arr){
    if(b <= max_a) break;
    H -= b;
    ncount++;
    if(H <= 0){
      H = 0;
      break;
    }
  }

  std::cout << ncount+(H+max_a-1)/max_a << std::endl;

  return 0;
}



Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main() {
	int abc[100], youso;
	cin >> youso;
	for (int i = 0; i < youso; ++i) {
		cin >> abc[i];
	}
	int damy, time = 0;
	for (int i = 0; i < youso - 1; ++i) {
		for (int ii = youso - 1; ii > i; --ii) {
			if (abc[ii - 1] > abc[ii]) {
				damy = abc[ii - 1];
				abc[ii - 1] = abc[ii];
				abc[ii] = damy;
				++time;
			}
		}
	}
	for (int i = 0; i < youso-1; ++i) {
		cout << abc[i]<<" ";
	}
	cout << abc[youso - 1] << endl << time << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
ll mod = 1e9 + 7;

using namespace std;



int main()
{
	int W,a,b;

	cin >>W>>a>>b;
	if ((a + W) < b)
	{
		cout << b - a - W << endl;
	}
	else if ((b + W) < a)
	{
		cout << a - b - W << endl;
	}
	else
	{
		cout << 0 << endl;
	}
	

	return 0;
}

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

int main() {
  int n, a, min, max;
  cin >> n;
  long sum;
  min = 1000000; max = -1000000; sum = 0;
  for (int i = 0; i < n; i ++) {
    cin >> a;
    if (a < min) min = a;
    if (a > max) max = a;
    sum += a;
  }
  cout << min << " " << max << " " << sum << endl;
}



Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<pair<int,int>> vip;

#define ZOOM ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define ff it->first
#define ss it->second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define LOOP_IT(s) for(auto it=(s).begin();it!=(s).end();++it)


ull power(ull x, ull y)
{
    ull res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x*1ull);

        y = y>>1;
        x = (x*x*1ull);
    }
    return (res);
}

int main(int argc,char* argv[])
{
    ZOOM

    ull h,ans=0,j=0;
    cin>>h;

    while(h>0)
    {
        ans+=power(2,j);
        ++j;
        h=h/2;
    }
    cout<<ans;


    return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    int a,b;
    cin>>a>>b;
    if(a%3==0||b%3==0||(a+b)%3==0) cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll dp[350][350];
int n;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    ll sum=0;
    vector<vector<ll>> a(n,vector<ll>(n));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
            dp[i][j]=a[i][j];
            sum+=a[i][j];
        }
    }
    sum/=2;
    int V=n;
    for(int k=0;k<V;k++)
                for(int i=0;i<V;i++)
                   for(int j=0;j<V;j++)
                      dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
         
   for(int i=0;i<n;i++){
       for(int j=i;j<n;j++){
           if(i==j)continue;
           bool flag=true;
           for(int k=0;k<n;k++){
               if(i==k||j==k)continue;
               if(dp[i][k]+dp[k][j]<a[i][j]){
                   cout<<-1<<endl;
                   return 0;
               }
               else if(flag&&dp[i][k]+dp[k][j]==a[i][j]){
                   flag=false;
                   sum-=a[i][j];
               }
           }
       }
   }
   cout<<sum<<endl;
}


Measured memory_bytes: 1792
import java.util.*;
import java.io.*;

import static java.lang.Character.isUpperCase;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        String str = in.next();



        if(str.equals("ABC"))
        {
            System.out.println("ARC");
        }
        else if(str.equals("ARC"))
        {
            System.out.println("ABC");
        }
        
        
        else{}
    }




    }






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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

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

  ll n,m,l;
  cin>>n>>m>>l;
  vector<vector<ll>> dist1 (n,vector<ll>(n,INF));
  vector<vector<ll>> dist2 (n,vector<ll>(n,INF));
  rep(i,m){
    ll a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    chmin(dist1[a][b],c);
    chmin(dist1[b][a],c);
  }
  ll q;
  cin>>q;
  vector<pair<ll,ll>> query;
  rep(i,q){
    ll s,t;
    cin>>s>>t;
    s--;t--;
    query.emplace_back(s,t);
  }

  rep(k,n)rep(i,n)rep(j,n){
    chmin(dist1[i][j],dist1[i][k]+dist1[k][j]);
  }

  rep(i,n)rep(j,n){
    if(dist1[i][j]<=l)dist2[i][j]=1;
  }

  rep(k,n)rep(i,n)rep(j,n){
    chmin(dist2[i][j],dist2[i][k]+dist2[k][j]);
  }

  rep(i,q){
    ll s,t;tie(s,t)=query[i];
    if(dist2[s][t]!=INF)cout<<(dist2[s][t]-1)<<endl;
    else cout<<(-1)<<endl;
  }

}


Measured memory_bytes: 3836
package main

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

var (
	a      []int
	dp     [][][2]int
	calced [][]bool
)

func f(u, l, r int) [2]int {
	if l > r {
		return [2]int{0, 0}
	}
	if calced[l][r] {
		return dp[l][r]
	}
	calced[l][r] = true
	t0 := f(u^1, l+1, r)
	t0[u] += a[l]
	t1 := f(u^1, l, r-1)
	t1[u] += a[r]
	if t0[u]-t0[u^1] > t1[u]-t1[u^1] {
		dp[l][r] = t0
	} else {
		dp[l][r] = t1
	}
	return dp[l][r]
}

func main() {
	N := readInt()
	a = make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = readInt()
	}

	dp = make([][][2]int, N)
	calced = make([][]bool, N)
	for i := 0; i < N; i++ {
		dp[i] = make([][2]int, N)
		calced[i] = make([]bool, N)
	}

	t := f(0, 0, N-1)
	fmt.Println(t[0] - t[1])
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 96256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 300020
#define MAXN 100000
using namespace std;
int n,m,sz[M],K[M],res,mp[2000000];
int od[M],ans; LL p[M],pri[M],t[M]; bool isp[M];
bool cmp(int x,int y){return t[x]<t[y];}
LL read(){
	LL nm=0,fh=1; char cw=getchar(); for(;!isdigit(cw);cw=getchar());
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return nm*fh;
}
int main(){
//	freopen("cc.in","r",stdin);
	memset(isp,true,sizeof(isp));
	for(int i=2;i<MAXN;i++){
		if(!isp[i]) continue; pri[++m]=i;
		for(int j=(i<<1);j<MAXN;j+=i) isp[j]=false;
	}
	n=read();
	for(int j,i=1;i<=n;i++){
		for(p[i]=read(),K[i]=sz[i]=0,j=t[i]=1;j<=308;j++){
			if(p[i]%pri[j]) continue; int cnt=0;
			while(!(p[i]%pri[j])) p[i]/=pri[j],++cnt; cnt%=3;
			if(cnt) K[i]|=((cnt&1)<<sz[i]),sz[i]++,t[i]*=pri[j];
		}
		if(p[i]>1ll){
			if(p[i]<MAXN) K[i]|=(1<<sz[i]),sz[i]++,t[i]*=p[i];
			else {
				LL qq=sqrt(p[i]);
				if(qq*qq!=p[i]) ans++,i--,n--;
				else sz[i]++,t[i]*=qq;
			}
		}
	}
	for(int i=1;i<=n;i++) od[i]=i; sort(od+1,od+n+1,cmp);
	for(int l=1,r;l<=n;l=r+1){
		for(r=l;r<n&&t[od[r]]==t[od[r+1]];r++);
		if(t[od[l]]==1){ans++;continue;}
		int maxn=(1<<sz[od[l]])-1;
		for(int i=l;i<=r;i++) mp[K[od[i]]]++;
		for(int i=l;i<=r;i++){
			int x=K[od[i]],ot=(maxn^K[od[i]]);
			if(mp[x]>=mp[ot]) ans+=mp[x],mp[x]=mp[ot]=0;
		}
	} printf("%d\n",ans); return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    ll A,V,B,W,T; cin >> A >> V >> B >> W >> T;
    if(A!=B && V<=W) cout << "NO" << en;
    else if(A==B) cout << "YES" << en;
    else if(A<B){
        A += V*T;
        B += W*T;
        if(B<=A) cout << "YES" << en;
        else cout << "NO" << en;
    }
    else{
        A -= V*T;
        B -= W*T;
        if(A<=B) cout << "YES" << en;
        else cout << "NO" << en;
    }
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

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

template <class Abel> struct BIT {
    const Abel UNITY_SUM = 0;                       // to be set
    vector<Abel> dat;
    
    /* [1, n] */
    BIT(int n) : dat(n + 1, UNITY_SUM) { }
    void init(int n) { dat.assign(n + 1, UNITY_SUM); }
    
    /* a is 1-indexed */
    inline void add(int a, Abel x) {
        for (int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }
    
    /* [1, a], a is 1-indexed */
    inline Abel sum(int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i)
            res = res + dat[i];
        return res;
    }
    
    /* [a, b), a and b are 1-indexed */
    inline Abel sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat.size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	int ok=1000000000,ng=0;
	while (ok-ng>1)
	{
		int mid=(ok+ng)/2;
		long long now=0LL;
		BIT<long long> bit(2*n+5);
		int s=0;
		bit.add(n+1,1LL);
		for (int i = 0; i < n; ++i)
		{
			int tmp=1;
			if (a[i]>mid)
			{
				tmp=-1;
			}
			s+=tmp;
			now+=bit.sum(1,s+n+1);
			bit.add(s+n+1,1LL);
		}
		if (now>(long long)(n+1LL)*n/4LL)
		{
			ok=mid;
		}
		else
		{
			ng=mid;
		}
	}
	cout<<ok<<endl;
	return 0;
}


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

int main(){
	int N, a_min, a_max, a;
	cin >> N;
	a_min = 1000000000;
	a_max = 0;
	for(int i=0; i<N; i++){
		cin >> a;
		a_max = max(a, a_max);
		a_min = min(a, a_min);
	}
	cout << a_max - a_min << endl;
	return 0;
}


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

typedef pair<long, int> pi;

int main(){
  
  int N;
  long long L;
  cin >> N >> L;
  
  vector<long> x(N);
  long tmp, sum = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> tmp;
    sum += tmp;
    x.at(i) = tmp;
  }
  
  vector<int> ans(N - 1);
  bool flag = true;
  int x1 = 0, x2 = N - 1;
  
  for (int i = 0; i < N - 1; i++) {
    if (x.at(i) + x.at(i + 1) >= L) {
      x1 = i; x2 = i + 1;
      break;
    }
    if (i == N - 2) flag = false;
  }
  
  if (flag) {
    cout << "Possible" << endl;
    for (int i = 0; i < x1; i++) cout << i + 1 << endl;
    for (int i = N - 1; i > x2; i--) cout << i << endl;
    cout << x2;
  } else cout << "Impossible";
  
  return 0;
}

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

int main() {
  int W, H, C;
  cin >> W >> H >> C;
  int ans = 0;
  for (int i = min(W, H); i >= 1; i--) {
    if (max(W, H) % i == 0 && min(W, H) % i == 0) {
      ans = C * max(W, H) / i * min(W, H) / i;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3108
#include <stdio.h>

int main(void){

    long int n, a, b;
    long int s1, s2;

    scanf("%ld%ld%ld",&n,&a,&b);

    s1 = n / (a+b);
    s2 = n % (a+b);

    if(s2<=a){
        printf("%ld",s1*a+s2);
    }else{
        printf("%ld",s1*a+a);
    }

    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
vector <long long int>vec;
int main(){
    long long int n;
	cin>>n;
 	for(long long int i=1e6;i>0;i--){
	if(n%i==0){
	vec.push_back(i+(n/i));	
}
}
    sort(vec.begin(),vec.end());
	cout<<vec[0]-2;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <climits>
#include <vector>
#include <functional>

using namespace std;

const int INFINITY = INT_MAX;

struct Node{
  vector<int> edgeTo;
  vector<int> edgeCost;
  bool done;
  int cost;
};

class compf: public binary_function<struct Node, struct Node, bool>{
public:
  result_type operator()(first_argument_type first, second_argument_type second){
    return (first.cost - second.cost) > 0;
  }
};

int Dijkstra(int start, int goal, struct Node *town){
  priority_queue<struct Node, vector<struct Node> , compf> priQueue;

  town[start].cost = 0;
  priQueue.push(town[start]);


  while(priQueue.empty() == false){
    struct Node doneNode = priQueue.top(); priQueue.pop();
    if(doneNode.done == true) continue;
    doneNode.done = true;
    for(int i = 0; i < doneNode.edgeTo.size(); i++){
      int to = doneNode.edgeTo[i];
      unsigned int cost = (unsigned int)doneNode.cost + doneNode.edgeCost[i];
      if(cost < town[to].cost){
	town[to].cost = cost;
	priQueue.push(town[to]);
#if DEBUG
	printf("town No.%d is pushed.\n", i);
#endif
      }
    }
  }
#if DEBUG
  for(int i = 0; i < 7; i++){
    printf("i = %d, cost = %d\n", i, town[i].cost);
  }
#endif
  return town[goal].cost;
}

int main(){
  int n, m;
  cin >> n >> m;
  struct Node town[n + 1];

  for(int i = 0; i < n + 1; i++){
    town[i].done = false;
    town[i].cost = INFINITY;
  }

  for(int i = 0; i < m; i++){
    int a, b, c, d;
    char t;
    cin >> a >> t >> b >> t >> c >> t >> d;
    town[a].edgeTo.push_back(b);
    town[a].edgeCost.push_back(c);
    town[b].edgeTo.push_back(a);
    town[b].edgeCost.push_back(d);    
  }

  int start, yamazato, reward, polePrice;
  char t;
  cin >> start >> t >> yamazato >> t >> reward >> t >> polePrice;

  int gotoCost = Dijkstra(start, yamazato, town);

  for(int i = 0; i < n + 1; i++){
    town[i].done = false;
    town[i].cost = INFINITY;
  }

  int gobackCost = Dijkstra(yamazato, start, town);

  cout << reward - gotoCost - gobackCost - polePrice << endl;
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
 
int ary[10][10];
 
int main() {
        while(1) {
                static int n;
                memset(ary, 0, sizeof(ary));
                scanf(" %d", &n);
                if(!n)
                        break;
                for(int y = 0; y < n; y++) {
                        for(int x = 0; x < n; x++) {
                                static int t;
                                scanf(" %d", &t);
                                ary[y][x] = t;
                        }
                }
                vector<int> width;
                vector<int> height;
                for(int i = 0; i < n; i++) {
                        int sum = 0;
                        for(int j = 0; j < n; j++) {
                                sum += ary[i][j];
                        }
                        width.push_back(sum);
                }
                for(int i = 0; i < n; i++) {
                        int sum = 0;
                        for(int j = 0; j < n; j++) {
                                sum += ary[j][i];
                        }
                        height.push_back(sum);
                }
                int result = accumulate(height.begin(), height.end(), 0);
                
                for(int y = 0; y < n; y++) {
                        for(int x = 0; x < n; x++) {
                                printf("%5d", ary[y][x]);                       
                        }
                        printf("%5d\n", width[y]);
                }
                for(int i = 0; i < n; i++)
                        printf("%5d", height[i]);
                printf("%5d\n", result);
        }
        return 0;
} 

Measured memory_bytes: 0
def examB():
    from collections import deque
    St = S()
    que = deque()
    for s in St:
        if s=="B":
            if que:
                que.pop()
        else:
            que.append(s)
    ans = list(que)
    print("".join(map(str,ans)))


import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()

Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
struct T {
	unsigned char a,b;
};
T array[1000000];
int main(){
    int n,m,i,j;
    unsigned char a,b;
    string ca,cb;
    bool flag;
    while(cin >> n && n){
        flag = true;
        string out;
        memset(array,0,sizeof(array));
        for(i = 0;i < n;i++){
            cin >> a >> b;
            array[i].a = a;
            array[i].b = b;
        }
        cin >> m;
        for(i = 0;i < m;i++){
            cin >> a;
			ca = a;
            for(j = 0;j < n;j++){
            	cb = array[j].a;
            	if(ca == cb){
            		flag = false;
					break;
            	}
            }
            if(flag){
            	out += a;
            }
            else {
            	out += array[j].b;
            }
            flag = true;
        }
        cout << out << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>
int main(void){
  	char S[100];
  	scanf("%s",S);
  	int i, count = 0;
  	for(i=0;i<strlen(S)/2;i++){
    	if(S[i] != S[strlen(S)-1-i]){
          S[i] = S[strlen(S)-1-i];
          count++;
        }  
    }
  	printf("%d\n",count);
  
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

ll dp[440][440];

int main(){
  int n;
  cin>>n;
  ll a[n+1]={};
  ll sum[n+1]={};
  for(int i=1;i<=n;i++){
    cin>>a[i];
    sum[i]=sum[i-1]+a[i];
  }

  for(int i=1;i<=n;i++){
    for(int j=i+1;j<=n;j++){
      dp[i][j]=1e16;
    }
  }

  for(int len=1;len<n;len++){
    for(int l=1;l+len<=n;l++){
      int r=l+len;
      for(int k=l;k<r;k++){
        dp[l][r]=min(dp[l][r],dp[l][k]+dp[k+1][r]+sum[k]-sum[l-1]+sum[r]-sum[k]);
      }
    }
  }

  cout<<dp[1][n]<<endl;

  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct SegmentTree {
    struct Node {
        Node operator*(const Node& o) const {
            return { max(v, o.v) };
        }
        int v;
    };
    SegmentTree(int n) : e({ 0 }), n(n) {
        for (m = 2; m < n; m *= 2);
        t = vector<Node>(m + n + n % 2, e);
    }
    Node& operator[](int i) {
        return t[m + i];
    }
    const Node& root() const {
        return t[1];
    }
    void build() {
        for (int i = (n - 1 + m) / 2; i > 0; i--) t[i] = t[i * 2] * t[i * 2 + 1];
    }
    void update(int i, const Node& o) {
        for (t[i += m] = o; i /= 2, i > 0;) t[i] = t[i * 2] * t[i * 2 + 1];
    }
    Node query(int l, int r) {
        Node o[2] = { e, e };
        for (l += m, r += m; l < r; l /= 2, r /= 2) {
            if (r & 1) o[1] = t[--r] * o[1];
            if (l & 1) o[0] = o[0] * t[l++];
        }
        return o[0] * o[1];
    }
    void print() {
        for (int j = 1; j <= m; j *= 2) {
            int k = min(j * 2, m + n);
            for (int i = j; i < k; i++) {
                cout << t[i].v << " \n"[i == k - 1];
            }
        }
    }
    vector<Node> t;
    const Node e;
    int n, m;
};

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

    int n, k, c;
    cin >> n >> k >> c;

    string s;
    cin >> s;

    vector<int> a[2];
    for (int h = 0; h < 2; h++) {
        a[h] = vector<int>(n);
        int i = 0, l = 0;
        for (;;) {
            while (i < n && s[i] != 'o') a[h][i++] = l;
            if (i == n) break;
            a[h][i++] = ++l;
            for (int x = 0; x < c; x++) {
                if (i == n) break;
                a[h][i++] = l;
            }
            if (i == n) break;
        }
        reverse(s.begin(), s.end());
    }

    reverse(a[1].begin(), a[1].end());

    int d = max(c + 1, 2);
    SegmentTree st(n);
    for (int i = d; i < n; i++) {
        st[i].v = a[0][i - d] + a[1][i];
    }
    st.build();

    for (int i = 0; i < n; i++) {
        if (s[i] != 'o') continue;
        int r = 0;
        if (i > 0) r = max(r, a[0][i - 1]);
        if (i < n - 1) r = max(r, a[1][i + 1]);
        r = max(r, st.query(i + 1, min(i + d, n)).v);
        if (r < k) cout << i + 1 << '\n';
    }

    return 0;
}

Measured memory_bytes: 5268
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x;
  cin >> x;
  
  if ((x >= 400) && (x <= 599)) {
    cout << "8" << endl;
  }
  else if ((x >= 600) && (x <= 799)) {
    cout << "7" << endl;
  }
  else if ((x >= 800) && (x <= 999)) {
    cout << "6" << endl;
  }
  else if ((x >= 1000) && (x <= 1199)) {
    cout << "5" << endl;
  }
  else if ((x >= 1200) && (x <= 1399)) {
    cout << "4" << endl;
  }
  else if ((x >= 1400) && (x <= 1599)) {
    cout << "3" << endl;
  }
  else if ((x >= 1600) && (x <= 1799)) {
    cout << "2" << endl;
  }
  else if ((x >= 1800) && (x <= 1999)) {
    cout << "1" << endl;
  }
  else {
  }

  return 0;
}

Measured memory_bytes: 3580
N,M = list(map(int,input().split()))

A = list(map(int,input().split()))
s = 0
S = [0]
for i in range(N):
    s+=A[i]
    s=s%M
    S.append(s)

from collections import Counter

c = Counter(S)
count=0
for i in c.keys():
    count+=((c[i]-1)*c[i])//2

print(count)

Measured memory_bytes: 16556
s = input()
t = input()
ans = ""
for i in range(min(len(s),len(t))):
    ans += s[i]
    ans += t[i]
if len(s) != min(len(s),len(t)):
    ans += s[-1]
elif len(t) != min(len(s),len(t)):
    ans += t[-1]

print(ans)


Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
    int i,j;
    char a[5][5];
    for(i=0; i<2; i++)
        scanf("%s",a[i]);
    if(a[0][0]==a[1][2]&&a[0][1]==a[1][1]&&a[0][2]==a[1][0])
        printf("YES");
    else
        printf("NO");
    return 0;
}

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


int main()
{
int N , s=0;
cin >> N ;
int L[N];
for (int i =0; i<N; i++)
{
    cin >> L[i];
}
sort(L ,L+N);
for(int i =0 ; i<N-1; i++)
{
    s=s+L[i];
}
if(s>L[N-1])
    cout << "Yes";
else
    cout << "No";

    return 0;
}


Measured memory_bytes: 256