akhauriyash/Code-Regression huggingface dataset:
def main():
    n = int(input())
    inlis = list(map(int, input().split()))

    total = 0
    mae = 0

    for i in range(n):
        total += abs(inlis[i] - mae)
        mae = inlis[i]
    total += abs(inlis[-1])
    inlis.append(0)

    #i = 0
    if 0 <= inlis[0] and inlis[0] > inlis[1]:
        if inlis[1] >0:
            print(total - 2 * abs(inlis[1] - inlis[0]))
        else:
            print(total - 2 * abs(inlis[0]))
    elif 0 >= inlis[0] and inlis[0]< inlis[1]:
        if inlis[1] < 0:
            print(total - 2 * abs(inlis[1] - inlis[0]))
        else:
            print(total - 2 * abs(inlis[0]))
    else:
        print(total)

    for j in range(1, n):
        if inlis[j-1] <= inlis[j] <= inlis[j+1] or inlis[j-1]>= inlis[j] >= inlis[j+1]:
            print(total)
        elif inlis[j-1] <= inlis[j] and inlis[j] > inlis[j+1]:
            if inlis[j-1] >= inlis[j+1]:
                print(total - 2 * abs(inlis[j-1] - inlis[j]))
            else:
                print(total- 2 * abs(inlis[j+1] - inlis[j]))
        elif inlis[j-1]>= inlis[j] and inlis[j] < inlis[j+1]:
            if inlis[j-1] >= inlis[j+1]:
                print(total - 2 * abs(inlis[j+1] - inlis[j]))
            else:
                print(total - 2 * abs(inlis[j-1] - inlis[j]))
    



        


if __name__ == "__main__":
    main()

Measured memory_bytes: 20436
# include <bits/stdc++.h>
//# pragma GCC optimize("Ofast")
# define pb push_back
# define ll long long
# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define forn(i, n) for (int i = 0; i < int(n); i++)
# define ford(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define fore(i, l, r) for (int i = int(l); i < int(r); i++)
# define in freopen("out.txt", "r", stdout)
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
 
using namespace std;
 
const ll INF = 1e18;
const int mod = 1e9 + 7;
const ll N = 2e6 + 7;
typedef vector < vector < ll > > matrix;

int main()
{   
    speed;
    int n;
    cin >> n;
    vector < pair < int, int > > vc(n);
    vector < double > ans;
    forn( i, n ) cin >> vc[i].fi >> vc[i].se;
    sort(all(vc));
    do {
        double dist = 0;
        fore( i, 1, n ) {
            double d = pow(vc[i].fi - vc[i - 1].fi, 2) + pow( vc[i].se - vc[i - 1].se, 2 );
            d = sqrt(d);
            dist += d;
        }
        ans.pb(dist);
    }
    while ( next_permutation(all(vc)) );
    double sum = 0;
    for ( auto i: ans ) sum += i;
    cout << setprecision(15) << sum / ans.size();
    time;
}


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

#define int long long
#define INF 9223372036854775807

#define mod 1000000007

vector<int> Graph[100009];
int dp[2][100009];

void dfs(int node, int last){
    dp[0][node] = dp[1][node] = 1;
    for(int a : Graph[node]){
        if(a != last){
            dfs(a, node);
            dp[0][node]*=((dp[0][a]+dp[1][a])%mod);
            dp[0][node]%=mod;
            dp[1][node]*=dp[0][a];
            dp[1][node]%=mod;
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n-1; i++){
        int a, b;
        cin >> a >> b;
        Graph[a].push_back(b);
        Graph[b].push_back(a);
    }
    dfs(1,-1);
    cout << (dp[1][1]+dp[0][1])%mod << endl;
}


Measured memory_bytes: 14208
n, m = map(int, input().split())
l_max = 0
r_min = 100001
for i in range(m):
    l, r = map(int, input().split())
    l_max = max(l_max, l)
    r_min = min(r_min, r)

ans = max(r_min - l_max + 1, 0)
print(ans)


Measured memory_bytes: 9100
#include<stdio.h>

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

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,ans;
    cin>>n>>k;
    ans=1;
    for(int i=0;i<n;i++)
    {
        if(ans>k)
            ans+=k;
        else 
            ans*=2;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define ll long long
using namespace std;

struct UnionFind{
    public:
    vector<int> data;
    UnionFind(int sz){
        data.assign(sz, -1);
    }
    int find(int p){
        if(data[p]<0) return p;
        return data[p]=find(data[p]);
    }
    bool unite(int X, int Y){
        X=find(X), Y=find(Y);
        if(X==Y) return false;
        if(data[X]>data[Y]) swap(X, Y);
        data[X] += data[Y];
        data[Y]=X;
        return true;
    }
    int size(int k){
        return -data[find(k)];
    }
};

int main() {
	int N;
	cin >> N;
	vector<pair<ll, int>> vx(N), vy(N);
	for(int i=0; i<N; ++i){
	    ll x, y;
	    cin >> x >> y;
	    vx[i]=make_pair(x, i);
	    vy[i]=make_pair(y, i);
	}
	vector<pair<ll, pair<int, int>>> ed;
	sort(vx.begin(), vx.end());
	sort(vy.begin(), vy.end());
	for(int i=0; i+1<N; ++i){
	    ed.push_back(make_pair(vx[i+1].first-vx[i].first, make_pair(vx[i].second, vx[i+1].second)));
	    ed.push_back(make_pair(vy[i+1].first-vy[i].first, make_pair(vy[i].second, vy[i+1].second)));
	}
	sort(ed.begin(), ed.end());
	UnionFind uf(N);
	int cnt=1, now=0;
	ll ans=0;
	while(cnt<N){
	    if(uf.unite(ed[now].second.first, ed[now].second.second)){
	        ans += ed[now].first;
	        ++cnt;
	    }
	    ++now;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9584
// https://atcoder.jp/contests/abc170/tasks/abc170_d
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
using P = pair<int, ll>;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    sort(a.begin(), a.end());

    map<int, ll> dic;
    for (int i = 0; i < n; ++i)
    {
        ++dic[a[i]];
    }
    ll amax = *(a.rbegin());
    vector<bool> dp(amax + 1, true);
    for (int x = 0; x <= amax; ++x)
    {
        if (dic[x] > 0)
        {
            // x が数列 A の要素に含まれる場合
            // x より大きい x の倍数 y について dp[y] = false にする
            // これによって割り切れるか否かを判定する
            for (int y = 2 * x; y <= amax; y += x)
            {
                dp[y] = false;
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        if (dic[a[i]] == 1 && dp[a[i]])
        {
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 67324
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll = long long;
using namespace std;

int main(){
	ll n,m;
	cin>>n>>m;
	ll x=(1900*m+100*(n-m))*pow(2,m);
	cout<<x;

}

Measured memory_bytes: 256
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define pf push_front
#define ins insert

//{
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();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
unsigned XorShift(void){static unsigned x = 123456789;static unsigned y = 362436069;static unsigned z = 521288629;static unsigned w = 88675123;unsigned t;t = x ^ (x << 11);x = y; y = z; z = w;return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int n,ans;

main(){
	cin>>n;
	int a[n];rep(i,n)cin>>a[i];
	int sum=0;
	for(int l=0,r=0;l<n;l++){
		while(r<n&&(sum^a[r])==(sum+a[r])){
			sum+=a[r];
			r++;
		}
		ans+=r-l;
		if(l==r)r++;
		else{
			sum-=a[l];
		}
	}
	dans;
}

Measured memory_bytes: 1792
import sys
data = []
for line in sys.stdin:
	data.append(line.split())

S = []
T = []
ans = []
S = data[1]
T = data[3]

count = 0
for t in T:
    l = 0
    r = len(S)

    while l < r :
        i = (l + r) / 2
        if int(S[i]) < int(t) :
            l = i + 1
        elif int(S[i]) > int(t) :
            r = i
        else :
            count = count + 1
            break

print(count)


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

int main(){
    int n,a,b,c,d;
    cin >> n;
    a = n / 1000;
    b = n % 1000 / 100;
    c = n % 100 / 10;
    d = n % 10; 
    if(a+b+c+d == 7) cout << a << "+" << b << "+" << c << "+" << d << "=" << 7 << endl;
    else if(a+b-c+d == 7) cout << a << "+" << b << "-" << c << "+" << d << "=" << 7 << endl;
    else if(a-b+c+d == 7) cout << a << "-" << b << "+" << c << "+" << d << "=" << 7 << endl;
    else if(a+b+c-d == 7) cout << a << "+" << b << "+" << c << "-" << d << "=" << 7 << endl;
    else if(a-b-c+d == 7) cout << a << "-" << b << "-" << c << "+" << d << "=" << 7 << endl;
    else if(a+b-c-d == 7) cout << a << "+" << b << "-" << c << "-" << d << "=" << 7 << endl;
    else if(a-b+c-d == 7) cout << a << "-" << b << "+" << c << "-" << d << "=" << 7 << endl;
    else if(a-b-c-d == 7) cout << a << "-" << b << "-" << c << "-" << d << "=" << 7 << endl;
    return 0;
}


Measured memory_bytes: 256
"use strict";
function Main(input) {
    var lines = input.split("\n");
    var N = lines.shift() - 0;
    var strA = lines[0];
    var strB = lines[1];
    var strC = lines[2];
    var count = 0;
    var match = new Array(N).fill(0);
    for (var n = 0; n < N; n++) {
        if (strA.charAt(n) == strB.charAt(n)) {
            if (strA.charAt(n) == strC.charAt(n)) {
                match[n] = 3;
            } else {
                match[n] = 2;
            }
        } else if (strB.charAt(n) == strC.charAt(n)) {
            match[n] = 2;
        } else if (strA.charAt(n) == strC.charAt(n)) {
            match[n] = 2;
        } 
    }
    for (var n = 0; n < N; n++) {
        switch (match[n]) {
        case 3:
            break;
        case 2:
            count += 1;
            break;
        case 1:
        case 0:
            count += 2;
            break;
        }
    }
    console.log(count);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<stdio.h>
int main(void){
  char x[1000];
  int i=0;
  int sum=0;
  while(1){
    char x[1000]={};
    sum = 0;
    scanf("%s",x);
    if(x[0]=='0')return(0);
    i = 0;
    while(x[i]!=0){
      sum += x[i] - '1' + 1;
      i++;
    }
    printf("%d\n",sum);
  }
  return(0);
}

Measured memory_bytes: 1848
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
const ll INF = 1e18 ;
int main() {
  int A ,B ,C ;
  cin >> A >> B >> C ;
  int X , Y ;
  cin >> X >> Y ;
  ll ans = INF ;
  ll count = A*X + B*Y ;
  rep( i , min(X,Y) ){
    ans = min(count,ans)  ;
    count += 2*C - A - B  ;
    ans = min(count,ans)  ;
    //cout << count << endl ;
  }
  rep( i , max(X,Y) - min(X,Y) ){
    if( X >= Y ) count += 2*C - A ;
    else        count  += 2*C - B ;
    ans = min(count,ans)  ;
  }
  cout << ans << endl ;
}


Measured memory_bytes: 256
import sys

S = input()
T = input()
len_S = len(S)
len_T = len(T)

offset = len_S - len_T
while offset >= 0:
    found = True
    for i in range(offset, offset + len_T):
        if S[i] != T[i - offset] and S[i] != '?':
            found = False
            break
    if found:
        S = S[:offset] + T + S[offset + len_T:]
        print(S.replace('?', 'a'))
        sys.exit()
    offset -= 1
print('UNRESTORABLE')


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

// a XOR a= 0 (つまり-a= a)より
// XOR[A:B+1)= XOR[0:B+1) ^ -XOR[0:A)
//           = XOR[0:B+1) ^ XOR[0:A)
// これとXOR[0:4n)= 0 (各位のビットの1の個数が偶数)を組み合わせる
int main(){
  int64_t A,B;
  cin >> A >> B;

  int64_t ans= 0;
  for(int64_t i=((B+1)/4)*4; i<B+1; i++){
    ans^= i;
  }
  for(int64_t i=(A/4)*4; i<A; i++){
    ans^= i;
  }

  cout << ans << endl; 
}

Measured memory_bytes: 256
n = gets.to_i
a = Array.new(n+1, 0)
b = gets.split(" ").map do |x|
  v = x.to_i
  a[v] += 1
  v
end
sum = a.inject(0) do |r, x|
  r += (x * (x-1)) / 2
end
b.each_with_index do |x, i|
  puts sum - a[x] + 1
end

Measured memory_bytes: 23172
import heapq

n, m = map(int, input().split())

a = list(map(lambda x: (-1) * int(x), input().split()))

# a.sort(reverse=True)
heapq.heapify(a)

for i in range(m):
    product = heapq.heappop(a)
    product = (-1) * ((product * (-1)) // 2)
    heapq.heappush(a, product)
    # print(a)
print(sum(a) * (-1))

Measured memory_bytes: 14180
// Problem : B - FizzBuzz Sum
// Contest : AtCoder Beginner Contest 162
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"
#define lb "lower_bound"
#define ub "upper_bound"
#define bs "binary_search"

int dif(int a,int b){if(a > b)return a - b;else return b - a;}
int min(int a,int b){if(a > b)return b;else return a;}
int max(int a,int b){if(a > b)return a;else return b;}
int gcd(int a,int b){if(a == 0)return b;else return (a%b,b);}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    ll n,sum = 0,in;
    cin>>n;
    for(int i = 1;i <= n;i++)
    {
    	in = i;
    	if(in%5!=0 && in%3!=0)
    	sum+=in;
    }
    cout<<sum;
	return 0;
}


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

for i in range(N):
    a, b, c = map(int, input().split())
    list = [a, b, c]
    for j in range(2,0,-1):
        for k in range(j):
            if list[k]<list[k+1]:
                list[k], list[k+1] = list[k+1], list[k]
    if (list[0])**2 == (list[1])**2 + (list[2])**2 :
        print('YES')
    else:
        print('NO')


Measured memory_bytes: 5596
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var m = int.Parse(line[0]);
        var n = int.Parse(line[1]);
        var k = int.Parse(Console.ReadLine().Trim());
        var mapJ = new int[m, n];
        var mapO = new int[m, n];
        for (int i = 0; i < m; i++)
        {
            var s = Console.ReadLine().Trim();
            if (s[0] == 'J') mapJ[i, 0] = 1;
            else if (s[0] == 'O') mapO[i, 0] = 1;
            for (int j = 1; j < n; j++)
            {
                mapJ[i, j] = mapJ[i, j - 1];
                mapO[i, j] = mapO[i, j - 1];
                if (s[j] == 'J') mapJ[i, j]++;
                else if (s[j] == 'O') mapO[i, j]++;
            }
        }
        var mapJ2 = new int[m, n];
        var mapO2 = new int[m, n];
        for (int i = 0; i < m; i++)
            for (int j = 0; j < n; j++)
                if (i == 0)
                {
                    mapJ2[i, j] = mapJ[i, j];
                    mapO2[i, j] = mapO[i, j];
                }
                else
                {
                    mapJ2[i, j] = mapJ[i, j] + mapJ2[i - 1, j];
                    mapO2[i, j] = mapO[i, j] + mapO2[i - 1, j];
                }
        for (int i = 0; i < k; i++)
        {
            string[] line2 = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line2[0]) - 1;
            var b = int.Parse(line2[1]) - 1;
            var c = int.Parse(line2[2]) - 1;
            var d = int.Parse(line2[3]) - 1;
            var t = (c - a + 1) * (d - b + 1);
            var ansJ = 0; var ansO = 0;
            if (a == 0 && b >= 1)
            {
                ansJ = mapJ2[c, d] - mapJ2[c, b - 1];
                ansO = mapO2[c, d] - mapO2[c, b - 1];
            }
            else if (a == 0 && b == 0) { ansJ = mapJ2[c, d]; ansO = mapO2[c, d]; }
            else if (a >= 1 && b >= 1)
            {
                ansJ = mapJ2[c, d] - mapJ2[c, b - 1] - mapJ2[a - 1, d] + mapJ2[a - 1, b - 1];
                ansO = mapO2[c, d] - mapO2[c, b - 1] - mapO2[a - 1, d] + mapO2[a - 1, b - 1];
            }
            else
            {
                ansJ = mapJ2[c, d] - mapJ2[a-1, d];
                ansO = mapO2[c, d] - mapO2[a-1, d];
            }
            Console.WriteLine("{0} {1} {2}", ansJ, ansO, t - ansJ - ansO);
        }
    }
}


Measured memory_bytes: 33312
a,b,c = map(int, input().split())

sum = (a+b+c)

if a == b == c:
    print(0)
    exit()
else:
    for i in range(max(a,b,c)*3, 200, 3):
        if (i - sum) % 2 == 0:
            print((i - sum)//2)
            exit()

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void judgement(bool a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll i,j,N,H,W,ans;
  cin>>N>>H;
  vec v(N);
  if(N<10&&H<10){
    cout<<N*H<<endl;
  }else{
    cout<<-1<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

ll k,a,b;

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin>>k>>a>>b;
	if(k < 3)
	{
		cout<<k+1<<endl;
	}
	else if(b-a <= 2 || a-1 + 2 > k)
	{
		cout<<k+1<<endl;	
	}
	else
	{
		ll ans = 0;
		k -= a+1;
		ans = b;
		if(k % 2)
			ans += 1;
		ans += (b-a)*(k/2);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000000
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

vector<vector<ll>> dp(1001, vector<ll>(20000, INF));

int main(){
  ll H, N;
  cin >> H >> N;
  vector<ll> A(N), B(N);
  rep(i, N){
    cin >> A.at(i) >> B.at(i);
  }
  ll a = 0;
  rep(i, N){
    chmax(a, A.at(i));
  }
  rep(i, N+1){
    dp.at(i).at(0) = 0;
  }
  ll ans = INF;
  rep(i, N){
    rep(j, H+a){
      chmin(dp.at(i+1).at(j), dp.at(i).at(j));
      if(j >= A.at(i)){
        chmin(dp.at(i+1).at(j), dp.at(i+1).at(j-A.at(i))+B.at(i));
      }
      if(j >= H){
        chmin(ans, dp.at(i+1).at(j));
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 160640
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define repp(i,n) for(int (i) = 1; (i) <= (n); ++(i))
#define popcnt __builtin_popcount
#define all(v) v.begin(),v.end()
#define _Pi 3.1415926535
#define _MOD = 1e9+7;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
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;}
template<class T> T gcd(T a, T b){return b?GCD(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/GCD(a,b);}

int main(){
    int n,k,r,s,p; string t; cin >> n >> k >> r >> s >> p >> t;
    int ans = 0;
    string u;
    rep(i,n){
        if(t[i] == 'r') t[i] = 'p';
        else if(t[i] == 'p') t[i] = 's';
        else t[i] = 'r';
    }
    rep(i,n){
        if(i < k || (i >= k && u[i-k] != t[i])){
            if(t[i] =='p'){
                ans += p;
                u += 'p';
            }
            else if(t[i] == 'r'){
                ans += r;
                u += 'r';
            }
            else{
                ans += s;
                u += 's';
            }
        }
        else u += '0';
    }

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


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long 
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod 1000000009
using namespace std;
bool isprime(ll n)
{
    //if(n<2)
    //return false;
    if(n==1)
    return true;
    if(n==2 || n==3)
    return true;
    if(n%2==0)return false;
    for(ll i=3;i*i<=n;i+=2)
    {
        if(n%i==0)
        return false;
        
    }
    return true;
}
int gcd(ll a,ll b)
{
    if(a==0)
    return b;
    return gcd(b%a,a);
}
int lcm(ll a,ll b)
{
    return a*(b/gcd(a,b));
}
 set<ll> fac;
void allFactors(ll n)
{
   // set<ll> fac;
    for(ll i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            fac.insert(i);
            if(i!=n/i)
            {
                fac.insert(n/i);
               
            }
        }
    }
    //return fac.size();
}
bool threefactors(ll n)//when you have need of a no which is divisible by 1,itself,any other one no.
{
    ll p=sqrt(n);
    if(p*p==n)
    {
        if(isprime(p))
        return 1;
        else
        return 0;
    }
    else
    return 0;
}

int main()
{
     IOS
     //int w;
     //cin>>w;
     //while(w--)
     {
       int n;
       cin>>n;
       int a[n+1];
       for(int i=1;i<=n;i++)
       {
           cin>>a[i];
       }
      ll dp[10000000];
      for(int i=0;i<10000000;i++)
      dp[i]=mod;
      dp[1]=0;
      for(int i=1;i<n;i++)
      {
          for(int j=i+1;j<=i+2;j++)
          {
              if(j<=n)
              dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
          }
      }
      cout<<dp[n];
     }
     return 0;
} 
//ascii of a=97
//ascii of A=65
//ascii of 0=48


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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;

  int cnt[5] = {};
  for ( int i = 0; i < N; i++ ) {
    string S;
    cin >> S;

    if ( S[0] == 'M' ) {
      cnt[0]++;
    }
    if ( S[0] == 'A' ) {
      cnt[1]++;
    }
    if ( S[0] == 'R' ) {
      cnt[2]++;
    }
    if ( S[0] == 'C' ) {
      cnt[3]++;
    }
    if ( S[0] == 'H' ) {
      cnt[4]++;
    }
  }

  int ans = 0;
  for ( int i = 0; i < 5; i++ ) {
    for ( int j = i+1; j < 5; j++ ) {
      for ( int k = j+1; k < 5; k++ ) {
	ans += cnt[i]*cnt[j]*cnt[k];	
      }
    }
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FASTIO
#define endl "\n" // Since endl forces a buffer flush which slows down large I/O operations.
#define ff first
#define ss second
#define pb push_back
#define input(c, n)             \
	for (int i = 0; i < n; i++) \
		cin >> c[i];
#define exit_message(s) return 0 * printf(s)
#define show(c)           \
	for (auto i : c)      \
		cout << i << " "; \
	cout << "\n";
#define display(c, n)           \
	for (int i = 0; i < n; i++) \
		cout << c[i] << " ";    \
	cout << "\n";
#define forl(i, a, n) for (int i = a; i < n; i++)
#define dugbe(k) cout << "-\t> " << #k << " = " << k << "\n";

/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

using namespace std;
typedef long long ll;
typedef pair<int, int> pr;
typedef pair<ll, ll> prll;
typedef vector<int> vi;
typedef vector<ll> vill;
typedef vector<pr> vpr;
ifstream in("input.txt");
const ll mod = 1e9 + 7;
const int N = 1e5 + 5;

ll mod_pow(ll a, ll b)
{
	if (b == 0)
		return 1LL;

	ll res = mod_pow(a, b >> 1);
	res = (res * res) % mod;
	if (b & 1LL)
		res = (res * a) % mod;

	return res;
}

ll n, k;
ll h[N], cost[N];

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

	int n, k;
	cin >> n >> k;
	forl(i, 0, n)
	{
		cin >> h[i];
	}
	cost[0] = 0;
	forl(i, 1, n)
	{
		cost[i] = 1e9;
		for (int j = i - 1; j >= max(0, i - k); j--)
		{
			cost[i] = min(cost[i], cost[j] + abs(h[i] - h[j]));
		}
	}
	cout << cost[n - 1] << "\n";

	return 0;
}

Measured memory_bytes: 1792
def prime(num):
    snum=int(num**0.5)+1
    pn=[True]*(snum+1)
    pn[0]=False
    pn[1]=False
    for i in range(2,snum):
        if pn[i]:
            for j in range(i*2,snum+1,i):
                pn[j]=False
    return pn

def factorization(n,l):
    ans=[]
    tmp=n
    for i in range(2,len(l)):
        if l[i]==False:
            continue
        if tmp%l[i]==0:
            while tmp%i==0:
                ans.append(i)
                tmp//=i
    if ans==[]:
        ans.append(n)
    elif tmp!=1:
        ans.append(tmp)
    return ans


n=int(input())
p=prime(n)
s=factorization(n,p)
print(str(n)+":",end=' ')
print(*s)


Measured memory_bytes: 5752
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.Sumitrust_2019
{
    class B
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            for(int i = 1; i <= n; i++)
            {
                int tmp = (int)(i * (1.08));
                if (tmp == n)
                {
                    WriteLine(i);
                    return;
                }
            }
            WriteLine(":(");
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

void Insert();
void Delete();
void DeleteFirst();
void DeleteLast();
void Output();
int Search(int a);

typedef struct{
  int back;
  int next;
  int value;
}LIST;

LIST data[3000005];
int p = 2;

int main(){
  int n;
  string query;
  ios_base::sync_with_stdio(false);
  data[0] = ((LIST){0,1,-1});
  data[1] = ((LIST){1,0,-1});
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> query;
    if(query == "insert")Insert();
    else if(query == "delete")Delete();
    else if(query == "deleteFirst")DeleteFirst();
    else if(query == "deleteLast")DeleteLast();
  }
  Output();
  return 0;
}

void Insert(){
  int v;
  cin >> v;
  data[p].value = v;
  data[p].back = 0;
  data[p].next = data[0].next;
  data[0].next = p;
  data[data[p].next].back = p;
  p++;
  return;
}

void Delete(){
  int a,v;
  cin >> a;
  v = Search(a);
  if(!~v)return;
  
  data[data[v].back].next = data[v].next;
  data[data[v].next].back = data[v].back;
  return;
}

void DeleteFirst(){
  data[0].next = data[data[0].next].next;
  data[data[0].next].back = 0;
  return;
}

void DeleteLast(){
  data[1].back = data[data[1].back].back;
  data[data[1].back].next = 1;
  return;
}

void Output(){
  int v = data[0].next;
  while(1){
    cout << data[v].value;
    if(data[v].next == 1)break;
    cout << " ";
    v = data[v].next;
  }
  cout << endl;
  return;
}

int Search(int a){
  int v = data[0].next;
  while(1){
    if(data[v].value == a)return v;
    if(data[v].next == 1)break;
    v = data[v].next;
  }
  return -1;
}

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


#define REP(i,n) for(int i=0;i<(int)(n);i++)

int n;
vector<int> g[125252];

bool used[125252];
stack<int> hist;
int po = -1;

bool namo[125252];

void dfs(int p, int bef){
  if(used[p]){
    po = p;
    return;
  }
  used[p] = true;
  hist.push(p);
  for(int to : g[p])if(to != bef){
    dfs(to,p);
    if(po != -1)return;
  }
  hist.pop();
  used[p] = false;
}

int main(){
  scanf("%d",&n);
  REP(i,n){
    int u,v;
    scanf("%d%d",&u,&v);
    u--;v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(0,-1);
  assert(po != -1);
  namo[po] = true;
  while(hist.top() != po){
    namo[hist.top()] = true;
    hist.pop();
  }
  int q;
  scanf("%d",&q);
  while(q--){
    int a,b;
    scanf("%d%d",&a,&b);
    a--;b--;
    if(namo[a] && namo[b]){
      puts("2");
    }else{
      puts("1");
    }
  }
  return 0;
}


Measured memory_bytes: 14320
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int inf = 1001001001;

int main(){
  int n, x, y;
  cin >> n >> x >> y;
  x--; y--;
  vector<vector<int>> g(n);
  rep(i,n){
    if(i == 0) g[0].push_back(1);
    else if(i == n-1) g[n-1].push_back(n-2);
    else {
      g[i].push_back(i-1);
      g[i].push_back(i+1);
    }
    g[x].push_back(y);
    g[y].push_back(x);
    // x is smaller
    // the graph is 0-indexed 
  }

  static int l[2001][2001];// length from i to j;

  // BFS to fill the i to j length map.
  rep(st,n){
    queue<int> q;
    vector<bool> seen(n);
    seen = {0};
    q.push(st);
    seen[st]=1;
    l[st][st]=0;
    while(!q.empty()){
      int now = q.front(); q.pop();
      for(auto nxt : g[now]) {
        if(seen[nxt] == 1) continue;
        q.push(nxt);
        seen[nxt] = 1;
        l[st][nxt] = l[st][now]+1;
      }
    }
  }

  //make answes
  map<int,int> mp;
  rep(i,2001)rep(j,2001) mp[l[i][j]] += 1;

  for(int i = 1; i<n; i++){
    int ans = mp[i];
    ans /= 2;
    cout << ans << endl;
  }
    
  
}


Measured memory_bytes: 19444
import itertools
import math
def myAnswer(N:int,D:int,X:list)->int:
   l = [i for i in range(N)]
   total = 0
   for i in itertools.combinations(l,2):
      distance = 0
      for n in range(D):
         distance += (X[i[0]][n] - X[i[1]][n])**2
      distance = distance**0.5
      if(distance == math.ceil(distance)):
         total += 1
   return total

   

def modelAnswer():
   tmp=1
def main():
   N,D = map(int,input().split())
   X = []
   for _ in range(N):
      X.append(list(map(int,input().split())))
   print(myAnswer(N,D,X[:]))

if __name__ == '__main__':
   main()

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

int main(void)
{
    string  s;
    cin >> s;
    int c = 0;
    for(int i = 0; i < 4; i++)
    {
        if(s[i] == '+')
            c++;
        else if(s[i] == '-')
            c--;
    }
    cout << c << "\n";

}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#n = int(input())
s = input()
a = s[0] == s[-1]
b = len(s)%2==0
#print(a,b)

if a == b:
    print("First")
else:
    print("Second")

Measured memory_bytes: 3316
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to,cap,rev; 
	edge (int from, int to, int cap, int rev){
		this->from=from; this->to=to; this->cap=cap; this->rev=rev;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;


int n;
int t[110];
int m;
int p[110], x[110];
int main(){
	cin >> n;
	FORI(0, n) {
		cin >> t[i];
	}
	cin >> m;
	FORI(0, m) {
		cin >> p[i] >> x[i];
		p[i]--;
	}
	int sum = 0;
	FORI(0,n) {
		sum += t[i];
	}
	FORI(0, m) {
		cout << sum - t[p[i]] + x[i]<<endl;
	}
	return 0;
}


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

using ci = const int;
using ld = long double;
using llint = long long;
using ullint = unsigned long long;
using pii = pair <int,int>;
using pcc = pair <char,char>;
using pll = pair <llint,llint>;
using pss = pair <string,string>;
using vi = vector <int>;
using vb = vector <bool>;
using vll = vector <llint>;
using vii = vi::iterator;

#define INF (1<<30)
#define MOD 1000000007
#define mt make_tuple
#define all(c) c.begin(), c.end()
#define ms(name,val) memset(name, val, sizeof name)
#define np nullptr
// inline functions



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

    llint n, w, ans = 0;
    cin >> n >> w;
    vll dp((1e5)+5, 0);

    for (int t1 = 0; t1 < n; ++t1)
    {
        int wi, vi;
        cin >> wi >> vi;

        for (int t2 = w; t2-wi >= 0; --t2)
        {
            dp[t2] = max(dp[t2], dp[t2-wi] + vi);
            ans = max(ans, dp[t2]);
        }
    }

    cout << ans << '\n';






























    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

    int n;
    while(cin>>n&&n!=0){
        int maxNum=0;
        for(int n1 = 0; n1 <= 53; n1++){
            int c=n-n1*n1*n1;c*=6;
            if(c<0)
                break;
            for(int n2=0;n2<=100;n2++){
                int t=n2*(n2+1)*(n2+2);
                if(t<=c)
                    maxNum=max(maxNum,t/6+n1*n1*n1);
            }
        }
        cout<<maxNum<<endl;
    }

    return 0;
}

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

#define int long long

#define MOD 1000000007
int n;
char s1[100];
char s2[100];

int memo[100][10][10];


int dp(int i, int t, int b){
    if(i == n) return 1;

    if(memo[i][t][b] != -1) return memo[i][t][b];

    int ans = 0;
    if(s1[i] == s2[i]){
        for(int c = 0;c < 3;c++){
            if(c != t && c != b){
                ans = (ans + dp(i+1, c, c)) % MOD;
            }
        }
    }else{
        for(int c = 0;c < 3;c++){
            for(int d = 0;d < 3;d++){
                if(c != t && d != b && c != d){
                    ans = (ans + dp(i+2, c, d)) % MOD;
                }
            }
        }
    }

    return memo[i][t][b] = ans;
}

signed main(){
    cin >> n >> s1 >> s2;

    memset(memo, -1, sizeof(memo));

    cout << dp(0, 3, 3) << endl;

    return 0;
}




Measured memory_bytes: 384
import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int n;
        while((n=sc.nextInt())!=0){
            int[]a=new int[26];
            sc.nextLine();
            boolean frag=false;
            int sum=0,ind=0;
            char c[]=sc.nextLine().replace(" ","").toCharArray();
            for(int i=0;i<n;i++){
                c[i]=(char)(((int)c[i])-((int)'A'));
                a[c[i]]++;
                int[]po=a.clone();
                Arrays.sort(po);
                sum=po[26-1];
                if(po[26-1]-po[26-2]>(n-i-1)){
                    ind=i+1;
                    frag=true;
                    break;
                }
            }
            for(int i=0;i<26;i++){
                if(a[i]==sum){
                    sum=i;
                    break;
                }
            }
            if(frag)
            System.out.println(((char)(sum+((int)'A')))+" "+ind);
            else System.out.println("TIE");
        }
    }
}



Measured memory_bytes: 54992
use std::io::{self, Read};

fn read_stdin() -> String {
    let mut buffer = String::new();
    io::stdin().read_to_string(&mut buffer).unwrap();
    buffer
}

fn parse_params(s: &str) -> Vec<i64> {
    let mut it = s.split_whitespace();

    let n: usize = it.next().unwrap().parse().unwrap();
    let mut v = Vec::with_capacity(n);

    for _ in 0..n {
        let d = it.next().unwrap().parse().unwrap();
        v.push(d);
    }

    v
}

fn main() {
    let buffer = read_stdin();
    let ds = parse_params(&buffer);

    let mut sum = 0;
    let mut sum_before = 0;

    for i in 1..ds.len() {
        sum_before += ds[i - 1];
        sum += ds[i] * sum_before;
    }

    println!("{}", sum);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S; cin >> S;
    vector<int> A(S.size() + 1, -1);
    if (S[0] == '<') A[0] = 0;
    if (S[S.size() - 1] == '>') A[A.size() - 1] = 0;
    for (int i = 1; i < A.size() - 1; i++) {
        if (S[i - 1] == '>' && S[i] == '<') A[i] = 0;
    }
    for (int i = 1; i < A.size(); i++) {
        if (S[i - 1] == '<' && A[i - 1] != -1) {
            A[i] = A[i - 1] + 1;
        }
    }
    for (int i = A.size() - 2; i >= 0; i--) {
        if (S[i] == '>' && A[i + 1] != -1) {
            A[i] = max(A[i], A[i + 1] + 1);
        }
    }
    cout << accumulate(begin(A), end(A), 0LL) << endl;
    return 0;
}


Measured memory_bytes: 2820
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    int max1=-1,max2=-1,p=-1;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(max1<a[i])
        {
            max1=a[i];
            p=i;
        }
    }
    a[p]=0;
    for(int i=0;i<n;i++)
    {
        if(max2<a[i])
        {
            max2=a[i];
        }
    }
    a[p]=max1;
    for(int i=0;i<n;i++)
    {
        if(a[i]==max1)
        {
            cout<<max2<<endl;
        }
        else
        {
            cout<<max1<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 2432
N=int(input().strip())
xyh=[]
for i in range(N):
    xyh.append(list(map(int, input().strip().split())))
xyh=sorted(xyh, key=lambda x:-x[2])

for cx in range(101):
    for cy in range(101):
        flag=True
        Hcand=-1
        for x,y,h in xyh:
            if h==0 and H>0:
                if H-abs(x-cx)-abs(y-cy)>0:
                    flag=False
                    break
            else:
                H= h+abs(x-cx)+abs(y-cy)
                if Hcand==-1:
                    Hcand=H
                else:
                    if Hcand!=H:
                        flag=False
                        break
        if flag:
            break
    if flag:
        break
print("{} {} {}".format(cx,cy,H))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define OUT(v) cout<<v<<endl
#define INF 1000000000

int N, A, B, C;

vector<int> usefor, l;
int solve(int idx, int c_a, int c_b, int c_c) {
  if (idx == N) {
    if (c_a == 0 || c_b == 0 || c_c == 0)
      return INF;
    int sum_a = 0;
    int sum_b = 0;
    int sum_c = 0;
    REP(i, N) {
      if (usefor[i] == 1)
        sum_a += l[i];
      if (usefor[i] == 2)
        sum_b += l[i];
      if (usefor[i] == 3)
        sum_c += l[i];
    }
    return (max(0, c_a-1) + max(0, c_b-1) + max(0, c_c-1)) * 10 + abs(A-sum_a) + abs(B-sum_b) + abs(C-sum_c) ;
  }
  int res = INF;
  usefor[idx] = 0;
  res = min(res, solve(idx+1, c_a, c_b, c_c));
  usefor[idx] = 1;
  res = min(res, solve(idx+1, c_a + 1, c_b, c_c));
  usefor[idx] = 2;
  res = min(res, solve(idx+1, c_a, c_b + 1, c_c));
  usefor[idx] = 3;
  res = min(res, solve(idx+1, c_a, c_b, c_c + 1));
  return res;
}
int main() {
  cin >> N >> A >> B >> C;

  l.resize(N);
  usefor.resize(N);
  REP(i, N)
    cin >> l[i];

  OUT(solve(0, 0, 0, 0));

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
using namespace std; typedef long long ll; const int INF=100; typedef pair<int,int> P;

int main() {
  int x,y,z; cin>>x>>y>>z;
  swap(x,y); swap(x,z);
  cout<<x<<" "<<y<<" "<<z<<endl;
}

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

int a[194];

int main() {
	int n;
	cin >> n;
	for(int i = 1; i <= n; ++i)
		cin >> a[i];
	int sum = 0;
	for(int i = 1; i <= n; ++i) {
		for(int j = i + 1; j <= n; ++j) {
			sum += a[i] * a[j];
		}
	}
	cout << sum;
}


Measured memory_bytes: 3624
import sys
import math
import bisect

def main():
    n = int(input())
    ans = n * (n + 1) // 2
    num_3 = n // 3
    num_5 = n // 5
    num_15 = n // 15
    ans -= num_3 * (num_3 + 1) // 2 * 3
    ans -= num_5 * (num_5 + 1) // 2 * 5
    ans += num_15 * (num_15 + 1) // 2 * 15
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9128
h,w = gets.split.map(&:to_i)
a = Array.new(h){ gets.chomp }

seen = Array.new(h){ Array.new(w){ false } }
DX = [ 0, 1, 0,-1, 1,-1, 1,-1]
DY = [ 1, 0,-1, 0, 1,-1,-1, 1]
inside = -> y, x { 0 <= y && y < h && 0 <= x && x < w }

bfs = -> sy,sx do
  que = [[sy,sx]]
  black = 0
  white = 0
  while que.size > 0
    y,x = que.pop
    next if seen[y][x]
    seen[y][x] = true
    a[y][x] == "#" ? black += 1 : white += 1
    4.times do |i|
      ny = y + DY[i]
      nx = x + DX[i]
      next unless inside[ny,nx]
      next if a[y][x] == a[ny][nx] # 同じ色なら対象外
      que << [ny,nx]
    end
  end
  return black * white
end

ans = 0
h.times do |y|
  w.times do |x|
    ans += bfs[y,x]
  end
end
puts ans

Measured memory_bytes: 29308
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

        var A = input[0];
        var B = input[1];

        if (1 <= A && A <= 9 && 1 <= B && B <= 9)
        {
            Console.WriteLine(A * B);
        }
        else
        {
            Console.WriteLine(-1);
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(b-a<0 and c-b<0 and c-a<0)
    cout<<"No";
   else if(b-a<=d and c-b<=d or c-a<=d)
    cout<<"Yes";
    
 
    else
    cout<<"No";
 
 
   return 0;
}

Measured memory_bytes: 256
import sys,os
while 1:
    t = int(input())
    if t == 0: break
    n = int(input())
    sf = [list(map(int, input().split())) for _ in range(n)]
    
    time = 0
    for i in sf:
        start,end = i
        if start > end:
            time += end - (start-24)
        else:
            time += end - start
    if time >= t:
        print("OK")
    else:
        print(t-time)


Measured memory_bytes: 5612
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb(a) push_back(a)
#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
const lint LINF = 1e18;



using namespace std;
int n,m;
vector<int> ken[200000];
int a[200000];
int b[200000];

int main(){
  cin >> n >> m;
  REP(i,m){
    int s,t;
    cin >> s >> t;
    a[i]= s;
    b[i]= t;
    ken[s].pb(t);
  }
  FOR(i,n) sort(ken[i].begin(),ken[i].end());
  REP(i,m){
    int t = lower_bound(ken[a[i]].begin(),ken[a[i]].end(),b[i])-ken[a[i]].begin()+1;
    string ans = "";
    string k = to_string(a[i]);
    //dump(ans);
    REP(i,6-k.size()) ans += "0";
    ans += k;
    //dump(ans);
    string k2 = to_string(t);
    REP(i,6-k2.size()) ans += "0";
    ans += k2;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 10112