akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define N 100050
using namespace std;
typedef long long ll;
char s[N],t[N];
int n,m,k,nn,mm;
inline ll gcd(ll x,ll y){
	if (y==0) return x;
	return gcd(y,x%y);
}
int main(){
	scanf("%d%d",&n,&m);
	scanf("%s%s",s+1,t+1);
	k=gcd(n,m);
	if (s[1]!=t[1]) {printf("-1\n");return 0;}
	if (k==1){
		printf("%lld\n",1ll*n*m/k);
		return 0;
	}
	nn=n/k,mm=m/k;
	for (int i=1,j=1;i<=n&&j<=m;i+=nn,j+=mm){
		if (s[i]!=t[j]) {printf("-1\n");return 0;}
	}
	printf("%lld\n",1ll*n*m/k);
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> void vdebug(vector<T> v){ cout << "vdebug" << endl; for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ cout << "adebug" << endl; reps(i, 0, n){ cout << arr[i] << " "; } cout << endl; }
template<typename T1, typename T2> void mdebug(map<T1, T2> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mldebug(multimap<T1, T2> mp){ cout << "mldebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mdebugr(map<T1, T2, greater<T1>> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mldebugr(multimap<T1, T2, greater<T1>> mp){ cout << "mldebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


struct Node{
    int x, y;
    Node(int x, int y):x(x),y(y){}
};

bool comp(pair<int, Node> p1, pair<int, Node> p2){
    return p1.first < p2.first;
}

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

    int h, w, d, a;
    cin >> h >> w >> d;
    vector<pair<int, Node>> xy[100000];
    rep(i, h){
        rep(j, w){
            cin >> a;
            xy[a%d].push_back(make_pair(a, Node(j, i)));
        }
    }

    ll cost[d][h*w/d+10];
    rep(i, d){
        sort(all(xy[i]), comp);
        cost[i][0] = 0;
        reps(j, 1, xy[i].size()-1){
            //if(j == 0) cost[i][j+1] = xy[i][j].second.x + xy[i][j].second.y;
            cost[i][j] = cost[i][j-1] 
                + abs(xy[i][j].second.x - xy[i][j-1].second.x) 
                + abs(xy[i][j].second.y - xy[i][j-1].second.y);
        }
    }

    int q;
    int l, r;
    cin >> q;
    rep(i, q){
        cin >> l >> r;
        int rest = l%d;
        int quotientl = l/d;
        int quotientr = r/d;
        if(rest == 0){
            quotientr--;
            quotientl--;
        }
        cout << cost[rest][quotientr] - cost[rest][quotientl] << endl;
    }

    return 0;
}


Measured memory_bytes: 13312
#include <bits/stdc++.h>
using namespace std;
#define test() int t; cin>>t; while(t--)
#define ll long long int
int mod = 1e9 + 7;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int a, b;
	cin >> a >> b;
	int ans = 0;
	int s = 1;
	while (s < b) {
		s--;
		s += a;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int n, a;
    cin >> n >> a;
    if(a >= n % 500) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <fstream>
#include <set>
#include <stack>
#include <queue>
#include <list>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define ss cout << " ";
#define ct(x) cout << x;
#define nn cout << "\n";
// // // // // // // // // // // // // // // // // // //


int q, n;
int main(){
    int rs = 0;
    cin >> n;
    int min = 1e9;
    for (int i = 0; i < n; i++){
        int temp;
        cin >> temp;
        if (temp <= min){
            min = temp;
            rs++;
        }
    }
    cout << rs;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int m = sc.nextInt();




			HashMap<Integer, HashSet<Edge>>graph = new HashMap<>();
			ArrayList<Edge> edgeList = new ArrayList<>();
			int[]nodeNum = new int[n+1];
			int[]nodeRevNum = new int[n+1];

			for (int i=1;i<=n;i++) {
				graph.put(i, new HashSet<Edge>());
			}

			for (int j=0;j<m;j++) {
				int a = sc.nextInt();
				int b = sc.nextInt();
				Edge edge = new Edge();
				edge.from=a;
				edge.to=b;
				edge.direction=1;

				graph.get(a).add(edge);
				graph.get(b).add(edge);
				edgeList.add(edge);
			}
			if (m%2==0) {
			ArrayDeque<Integer> q = new ArrayDeque<>();
			q.add(1);
			int number = 1;
			boolean[] used = new boolean[n+1];
			used[1]=true;
			while(!q.isEmpty()) {
				Integer intg = q.poll();
				nodeNum[intg]=number;
				nodeRevNum[number]=intg;
				number++;
				for (Edge e : graph.get(intg)) {
					int tmp = e.from+e.to-intg;
					if (!used[tmp]) {
						q.offer(tmp);
						used[tmp]=true;
					}
				}
			}

			for (int j=n;j>=1;j--) {
				int i = nodeRevNum[j];
				int sum = 0;
				for (Edge e : graph.get(i)) {
					if (e.from==i) {
						sum+=e.direction;
					} else  {
						sum+=(1-e.direction);
					}
				}

				if (sum%2!=0) {
					Edge min = null;
					for (Edge e : graph.get(i)) {
						if (min==null) {
							min=e;
						} else if (nodeNum[e.from+e.to-i] < nodeNum[min.from+min.to-i]) {
							min=e;
						}
					}
					min.direction=1-min.direction;
				}
			}

			for (Edge e : edgeList) {
				if (e.direction==1) {
					System.out.println(e.from+" "+e.to);
				} else {
					System.out.println(e.to+" "+e.from);
				}
			}
		} else {
			System.out.println(-1);
		}
	}
}


class Edge  {
	int from;
	int to;
	int direction; //1:from -> to

}



Measured memory_bytes: 138588
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#define RIGHT 1
#define LEFT -1
#define UP 2
#define DOWN -2
using namespace std;

int main(){
	int i,j,state,sy=0,sx=1,t_state;
	char row[5][4],col[4][5];

	cin>>row[0];
	for(i=0;i<4;i++){
		cin>>col[i];
		cin>>row[i+1];
	}

	for(i=0;i<5;i++){
		for(j=0;j<4;j++){
			row[i][j]=row[i][j]-'0';
		}
	}
	for(i=0;i<5;i++){
		for(j=0;j<4;j++){
			col[j][i]=col[j][i]-'0';
		}
	}

	cout<<"R"<<flush;
	state=RIGHT;
	while(sy || sx){
		switch(state){
			case RIGHT:
				if(sy>0 && col[sy-1][sx]){
					cout<<"U"<<flush;
					t_state=UP;
					sy--;
				}else if(sx<4 && row[sy][sx]){
					cout<<"R"<<flush;
					t_state=RIGHT;
					sx++;
				}else if(sy<4 && col[sy][sx]){
					cout<<"D"<<flush;
					t_state=DOWN;
					sy++;
				}else if(sx>0 && row[sy][sx-1]){
					cout<<"L"<<flush;
					t_state=LEFT;
					sx--;
				}
				break;
			case LEFT:
				if(sy<4 && col[sy][sx]){
					cout<<"D"<<flush;
					t_state=DOWN;
					sy++;
				}else if(sx>0 && row[sy][sx-1]){
					cout<<"L"<<flush;
					t_state=LEFT;
					sx--;
				}else if(sy>0 && col[sy-1][sx]){
					cout<<"U"<<flush;
					t_state=UP;
					sy--;
				}else if(sx<4 && row[sy][sx]){
					cout<<"R"<<flush;
					t_state=RIGHT;
					sx++;
				}
				break;
			case UP:
				if(sx>0 && row[sy][sx-1]){
					cout<<"L"<<flush;
					t_state=LEFT;
					sx--;
				}else if(sy>0 && col[sy-1][sx]){
					cout<<"U"<<flush;
					t_state=UP;
					sy--;
				}else if(sx<4 && row[sy][sx]){
					cout<<"R"<<flush;
					t_state=RIGHT;
					sx++;
				}else if(sy<4 && col[sy][sx]){
					cout<<"D"<<flush;
					t_state=DOWN;
					sy++;
				}
				break;
			case DOWN:
				if(sx<4 && row[sy][sx]){
					cout<<"R"<<flush;
					t_state=RIGHT;
					sx++;
				}else if(sy<4 && col[sy][sx]){
					cout<<"D"<<flush;
					t_state=DOWN;
					sy++;
				}else if(sx>0 && row[sy][sx-1]){
					cout<<"L"<<flush;
					t_state=LEFT;
					sx--;
				}else if(sy>0 && col[sy-1][sx]){
					cout<<"U"<<flush;
					t_state=UP;
					sy--;
				}
				break;
		}
		state=t_state;
	}

	cout<<endl;
	return 0;
}

Measured memory_bytes: 1132
S = input()

odd = len(S) % 2
little = odd + (1-odd)*2
start = len(S)-1-little

ans = 0
for i in range(start,0,-2):
  half = (i+1)//2
  a = S[:half]
  b = S[half:half*2]
  if a == b:
    #print(a,b)
    ans = len(a)*2
    break
    
    
print(ans)

Measured memory_bytes: 9080
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

#define MOD 2019

signed main() {
	int l,r;
	std::cin >> l >> r;
	if(r-l>=673){print(0);return 0;}
	int min = MOD;
	for(int i=l;i<r;i++) for(int j=i+1;j<=r;j++) min = std::min(min,(i*j)%MOD);
	print(min);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <algorithm>
using namespace std;

int main() {
    int A, B;
    cin >> A >> B;

    if (A + B == 3) {
        cout << 3 << endl;
    }
    else if (A + B == 4) {
        cout << 2 << endl;
    }
    else {
        cout << 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int search(int A[],int n,int key){
    int i = 0;
    A[n] = key;
    while(A[i] != key) i++;
    return i != n;
}

int main(){
    int i,n,A[10000+1],q,key,sum = 0;
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&A[i]);
    
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&key);
        if(search(A,n,key)) sum++;
    }
    printf("%d\n",sum);
    
    return 0;
}


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

using namespace std;

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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}


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

  ll a, b, k; cin >> a >> b >> k;
  bool init = 1;
  for(int i=0;i<k;++i) {
    if(init) {
      if(a % 2) a--;
      b += a / 2;
      a -= a / 2;
    } else {
      if(b % 2) b--;
      a += b / 2;
      b -= b / 2;
    }
    init = !init;
  }
  cout << a << " " << b << endl;

}


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

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define FORW(a, b, c) for(int a = b; a >= c; --a)
#define fi first
#define se second
#define pb push_back
//#define int long long

typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int N = 1e6 + 100;
const int oo = 1e8;
const int mod = 1e9 + 7;

int n;
int a[N];

int lucas(int k, int n)  {
    while(k > 0 || n > 0)   {
        int k1 = k % 2, n1 = n % 2;
        k /= 2; n /= 2;
        if(k1 > n1) return 0;
    }
    return 1;
}

int solve()    {
    int ans = 0;
    FOR(i, 1, n) ans = (ans + lucas(i - 1, n - 1) * a[i]) % 2;
    return ans;
}

signed main()  {
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);
    ios_base::sync_with_stdio(false); cout.tie(0);
    scanf("%d", &n);

    bool flag = 0;
    FOR(i, 1, n){
        char x; scanf(" %c", &x);
        a[i] = x - '0';
        a[i] -= 1;
        if(a[i] == 1) flag = 1;
    }
    int tmp = solve();
    if(tmp) return cout << tmp, 0;
    if(flag) return cout << "0", 0;
    FOR(i, 1, n) a[i] /= 2;
    tmp = 2 * solve();
    return cout << tmp, 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

int n,k;
cin >> n >> k;
string s;
cin >> s;

// ランレングス圧縮(両端に0個の1を置いておく)
vector<pii> v;
if(s[0] == '0') v.push_back(make_pair(1,0));
int cnt = 1;
rep(i,n) {
    if(i == n-1) {
        v.push_back(make_pair(s[n-1] - '0', cnt));
        break;
    }
    if(s[i] == s[i+1]) cnt++;
    else {
        v.push_back(make_pair(s[i]-'0',cnt));
        cnt = 1;
    }
}
if(s[n-1] == '0') v.push_back(make_pair(1,0));

int L = SZ(v);
int m = 0; // 0の区間の個数
rep(i,L) if(v[i].first == 0) m++;

if(m <= k) {
    cout << n << endl;
    return 0;
}

// m > k の場合

vi S(L+1);
rep(i,L) S[i+1] = S[i] + v[i].second;

int ans = 0;
for(int i = 0; i + 2*k < L; i = i + 2) {
    chmax(ans, S[i+2*k+1] - S[i]);
}

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

Measured memory_bytes: 1604
///AJoy Sarker ,CSE JAHANGIRNAGAR UNIVERSITY 48 Batch
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define inf INT_MAX/3
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 3.141592653589793
#define in scanf
#define out printf
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define FOR(i,a,b) for( int i=(a),_b=(b);i<=_b;i++)
#define DOW(i,b,a) for( int i=(b),_a=(a);i>=_a;i--)
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                prime[j] = false;
        }
    }
}
void pr (int f)
{
    if(f==1)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}
int main()
{
    fast;
    ll n;
    cin>>n;
    vector<ll>ara(n);
    for(int i=1;i<=n;i++)
    {
        ll a;
        cin>>a;
        ara.pb(a);
    }
    sort(ara.begin(),ara.end(),greater<ll>());
    ll A=0,B=0;
   // cout<<ara[0]<<ara[1];
    for(int i=0;i<ara.size();i++)
    {
        if(i%2) A+=ara[i];
        else    B+=ara[i];
    }
    cout<<abs(A-B)<<endl;
    return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> s(n+1);
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        s[a]++;
        s[b]--;
    }
    vector<int> g(n+1);
    for(int i = 1; i <= n; i++)
    {
        g[i] = g[i-1] + s[i];
    }
    for(int i = 0; i <= n; i++)
    {
        if(g[i] % 2 != 0)
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 1024
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ h, w ] <- readInts
	print $ ( h - 1 ) * ( w - 1 )


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
unsigned long long a,b,x,tot,s;
int main()
{
	cin>>a>>b>>x;
	if(a%x==0)s=a/x;
	else s=a/x+1;
	tot=b/x;
	printf("%lld",tot-s+1);
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var p = Console.ReadLine().ToInt();
		Console.WriteLine(p * 2.0 * Math.PI );
		
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 27620
#include<bits/stdc++.h>
#define fl(i,a,n)      for(int i=a;i<=n;i++)
#define pb             push_back
#define int            long long int
#define ump            unordered_map
#define pii            pair<int,int>
#define ff             first
#define ss             second
#define PI             3.1415926535898
#define inf            1e18
#define vi             vector<int>
#define endl           "\n"
#define print(a)       for(auto x:a){cout<<x<<" ";}cout<<endl;
#define mod            1000000007
#define ONLINE_JUDGE
using namespace std;
template <typename Arg, typename... Args>
void db(Arg&& arg, Args&&... args) {
    cout << std::forward<Arg>(arg);
    using expander = int[];
    (void)expander{0, (void(cout << ',' << std::forward<Args>(args)), 0)...}; cout << endl;
}
inline void solve() {
    int n; cin >> n;
    vi a(n);
    int s = 0;
    fl(i, 0, n - 1) {
        cin >> a[i];
    }
    int prev = a[0];
    fl(i, 1, n - 1) {
        if (a[i] < prev) {
            s += abs(a[i] - prev);
        }
        else {
            prev = a[i];
        }
    }
    cout << s << endl;
}
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    // cin >> t;
    fl(i, 1, t)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 4776
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] arr = sc.next().toCharArray();
        int length = arr.length;
        long[][] dp = new long[length + 1][2];
        dp[0][0] = 1;
        for (int i = 1; i <= length; i++) {
            if (arr[i - 1] == '1') {
                dp[i][0] = dp[i - 1][0] * 2 % MOD;
                dp[i][1] = (dp[i - 1][0] + dp[i - 1][1] * 3) % MOD;
            } else {
                dp[i][0] = dp[i - 1][0];
                dp[i][1] = dp[i - 1][1] * 3 % MOD;
            }
        }
        System.out.println((dp[length][0] + dp[length][1]) % MOD);
    }
}

Measured memory_bytes: 29612
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<62);
const double inf=pow(10,10);
const ld pi=acosl(1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

int main(){
	string s;cin>>s;
	ll n = s.size();
	ll ans=0;
	ll index=0;
	rep(i,n){
		if(s[i]=='W'){
			ans+=i-index;
			index++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        

fast();
//ll t;cin>>t;while(t--)
{
    ll n,ans=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
      ll x;
      cin>>x;
      ans+=(x-1);
    }
    cout<<ans<<endl;
}
return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
AB = [0] * N
for i in range(N):
    AB[i] = list(map(int, input().split()))

AB = sorted(AB)
cnt = 0
ans = 0

for e in AB:
    if cnt + e[1] < M:
        ans += e[0] * e[1]
        cnt += e[1]
    else:
        ans += e[0] * (M - cnt) 
        break

print(ans)

Measured memory_bytes: 28656
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int max = 0;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int h = sc.nextInt();
            if(h >= max){
                ans++;
                max = h;
            }
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 21716
#include<stdio.h>
int main(void){
	unsigned int c[3][3],i=0,count=0;

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

	i=0;

	for(i=0;i<=2;i++){
		if((c[i][0]-c[(i+1)%3][0]==c[i][1]-c[(i+1)%3][1])&&(c[i][0]-c[(i+1)%3][0]==c[i][2]-c[(i+1)%3][2])){
			count++;
		}
		if((c[0][i]-c[0][(i+1)%3]==c[1][i]-c[1][(i+1)%3])&&(c[0][i]-c[0][(i+1)%3]==c[2][i]-c[2][(i+1)%3])){
			count++;
		}
	}

	if(count==6){
		printf("Yes");
	}else{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
# cf16-exhibition-final-openA - 1D Matching
def calc(x, y, total):
    MOD = 10 ** 9 + 7
    if y:
        total = (total * y) % MOD
        y -= 1
    else:
        x += 1
    return x, y, total


def main():
    # sort A, B and the lines between A, B shouldn't cross
    # cross <-> not min distance
    N, *AB = map(int, open(0))
    C = sorted([(i, 1) for i in AB[:N]] + [(i, 0) for i in AB[N:]])
    ans, a, b = 1, 0, 0
    for i, t in C:
        if t:  # laptop
            a, b, ans = calc(a, b, ans)
        else:  # power sources
            b, a, ans = calc(b, a, ans)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 30680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n, l;
  cin >> n >> l;
  deque <ll> d;
  rep(i, n) {
    ll a;
    cin >> a;
    d.push_back(a);
  }
  ll res = 0;
  rep(i, l+1) {
    rep(j, i+1) {
      deque <ll> sub_d = d;
      vector <ll> u;
      ll tmp = 0;
      rep(k, j) {
        if (sub_d.size()) {
          tmp += sub_d.front();
          u.push_back(sub_d.front());
          sub_d.pop_front();
        }
      }
      rep(k, i-j) {
        if (sub_d.size()) {
          tmp += sub_d.back();
          u.push_back(sub_d.back());
          sub_d.pop_back();
        }
      }
      sort(u.begin(), u.end());
      rep(k, l-i) {
        if (k < u.size()) {
          if (u.at(k) < 0) tmp -= u.at(k);
        }
      }
      res = max(res, tmp);
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
n = int(input())
alist = list(map(int, input().split()))

count = 0
for i in range(n-2):
  if (alist[i] < alist[i+1] and alist[i+1] < alist[i+2]) or (alist[i] > alist[i+1] and alist[i+1] > alist[i+2]):
    count += 1
print(count)

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n;
  cin >> n;

  vi a(n);
  rep(i,0,n) cin >> a[i];

  const ll mod = 1e9+7;

  ll sm = 0, ans = 0;
  rep(i,0,n) {
    ans += a[i]*sm%mod;
    ans %= mod;
    sm += a[i]%mod;
    sm %= mod;
  } 
  cout << ans << '\n';
}

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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

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

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

int solve(string s) {
  int res = 0;
  for (uint i = 0; i < s.size() - 2; ++i) {
    if (s.substr(i, 3) == "101") {
      chmax(res, solve(s.substr(0, i) + "010" + s.substr(i + 3)) + 1);
    }
  }
  return res;
}

int main() {
  //*
  int n, res = 0;
  string s;
  cin >> n >> s;
  if (n < 3) {
    cout << 0 << endl;
    return 0;
  }
  /*/
  int n = 10;
  for (int _ = 0; _ < (1 << n); ++_) {
    string s;
    int res = 0;
    for (int i = 0; i < n; ++i) {
      if ((_ >> i) % 2) s += "0";
      else s += "1";
    }
    //*/
  pair<int, int> dp[2][6];
  for (int i = 0; i < 6; ++i) dp[0][i] = make_pair(-1, -1);
  if (s.substr(0, 2) == "00") dp[0][0] = make_pair(0, 0);
  if (s.substr(0, 2) == "01") dp[0][1] = make_pair(0, 0);
  if (s.substr(0, 2) == "10") dp[0][2] = dp[0][3] = make_pair(0, 0);
  if (s.substr(0, 2) == "11") dp[0][4] = dp[0][5] = make_pair(0, 1);
  for (int i = 2; i < n; ++i) {
    for (int j = 0; j < 6; ++j) dp[1][j] = make_pair(-1, -1);
    if (s[i] == '0') {
      if (dp[0][0].first >= 0) dp[1][0] = dp[0][0];
      if (dp[0][1].first >= 0) {
        dp[1][2] = dp[0][1];
        dp[1][3] = dp[0][1];
      }
      if (dp[0][2].first >= 0) chmax(dp[1][0], make_pair(dp[0][2].first, 0));
      if (dp[0][4].first >= 0) {
        chmax(dp[1][2], dp[0][4]);
        chmax(dp[1][2], dp[0][5]);
        if (dp[1][3].first + dp[1][3].second < dp[0][5].first + dp[0][5].second) dp[1][3] = dp[0][5];
      }
    } else {
      if (dp[0][0].first >= 0) dp[1][1] = dp[0][0];
      if (dp[0][1].first >= 0) dp[1][4] = dp[1][5] = make_pair(dp[0][1].first, 1);
      if (dp[0][2].first >= 0) {
        chmax(dp[1][1], make_pair(dp[0][2].first, 0));
        dp[1][2] = make_pair(dp[0][2].first + 1, 0);
        chmax(dp[1][2], make_pair(dp[0][3].first + 1, 0));
        dp[1][3] = dp[1][2];
        if (dp[0][2].second) {
          chmax(dp[1][0], make_pair(dp[0][2].first + dp[0][2].second + 1, 0));
        }
        if (dp[0][3].second) {
          chmax(dp[1][0], make_pair(dp[0][3].first + dp[0][3].second + 1, 0));
        }
      }
      if (dp[0][4].first >= 0) {
        chmax(dp[1][4], make_pair(dp[0][4].first, dp[0][4].second + 1));
        if (dp[1][5].first + dp[1][5].second < dp[0][5].first + dp[0][5].second + 1) dp[1][5] = make_pair(dp[0][5].first, dp[0][5].second + 1);
      }
    }
    //for (int j = 0; j < 6; ++j) cerr << "(" << dp[1][j].first << "," << dp[1][j].second << ")";
    //cerr << endl;
    for (int j = 0; j < 6; ++j) dp[0][j] = dp[1][j];
  }
  for (int i = 0; i < 6; ++i) res = max(res, dp[0][i].first);
  /*
  if (res != solve(s)) {
    cout << s << " " << res << " " << solve(s) << endl;
    return 0;
  }
}
  /*/
  cout << res << endl;
  //*/
}



Measured memory_bytes: 1172
use std::io::stdin;

#[derive(Debug)]
pub struct SegTree {
    size: usize,
    sum: Vec<i64>,
}

impl SegTree {
    pub fn new(n: i64) -> Self {
        let mut size = 1;
        while size <= n {
            size *= 2;
        }
        return SegTree {
            size: size as usize,
            sum: vec![0; (size * 2) as usize],
        };
    }
    pub fn update(self: &mut Self, i: usize, x: i64) {
        let mut i = self.size + i - 1;
        self.sum[i] = x;
        while i > 0 {
            i = (i - 1) / 2;
            self.sum[i] = self.sum[2 * i + 1] + self.sum[2 * i + 2];
        }
    }
    pub fn total(self: &mut Self) -> i64 {
        return self.sum[0];
    }
}

#[test]
fn segtree_test() {
    let mut t = SegTree::new(10);
    assert_eq!(t.size, 16);
    assert_eq!(t.total(), 0);
    println!("{:?}", t);
    for x in 0..10 {
        t.update(x, 1);
    }
    println!("{:?}", t);
    assert_eq!(t.total(), 10);
    t.update(1, 200);
    assert_eq!(t.total(), 209);
    t.update(2, 200);
    assert_eq!(t.total(), 408);
}

fn main() {
    let n: i64 = {
        let mut buf = String::new();
        stdin().read_line(&mut buf).unwrap();
        buf.split_whitespace().next().unwrap().parse().unwrap()
    };
    let a : Vec<_>= {
        let mut buf = String::new();
        stdin().read_line(&mut buf).unwrap();
        buf.split_whitespace().filter_map(|x| x.parse::<i64>().ok()).collect()
    };
    let mut segtree = SegTree::new(100001);
    let mut count = vec![0; 100001];
    for x in a {
        count[x as usize] += 1;

        segtree.update(x as usize, count[x as usize] * (x as i64));
    }

    let q: i64 = {
        let mut buf = String::new();
        stdin().read_line(&mut buf).unwrap();
        buf.split_whitespace().next().unwrap().parse().unwrap()
    };


    for _ in 0..q {
        let chars : Vec<_>= {
            let mut buf = String::new();
            stdin().read_line(&mut buf).unwrap();
            buf.split_whitespace()
                .filter_map(|x| x.parse::<usize>().ok())
                .collect()
        };
        if let &[b, c,..] = chars.as_slice()
        {
            count[c] += count[b];
            count[b] = 0;
            segtree.update(c as usize, count[c] * (c as i64));
            segtree.update(b as usize, 0);
            println!("{}", segtree.total());
        }
    }
}


Measured memory_bytes: 5068
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <sstream>
#include <vector>
#include <cstring>
#include <map>
#include <cassert>
using namespace std;

int dp[31][1<<16];

long long P;

long long bpow(long long A,long long B){
	return B ? bpow(A*A%P,B/2) * (B&1?A:1)%P : 1;
}
long long inv(long long n){
	if(n==0)throw "NG";
	return bpow(n,P-2);
}
long long A();
long long B();
long long C();

string s;
int p;

long long A(){
	long long l = B();
	while(s[p] == '+' || s[p] == '-' ){
		if( s[p] == '+' ){
			p++;
			l += B();
			l %= P;
		}else{
			p++;
			l -= B();
			l %= P;
			l += P;
			l %= P;
		}
	}
	return l;
}
long long B(){
	long long l = C();
	while(s[p] == '*' || s[p] == '/' ){
		if( s[p] == '*' ){
			p++;
			l *= C();
			l %= P;
		}else{
			p++;
			l *= inv(C());
			l %= P;
		}
	}
	return l;
}
long long C(){
	if( s[p] == '(' ){
		p++;
		long long res = A();
		p++;
		return res;
	}
	if( s[p] == '-' ){
		p++;
		return -C();
	}
	long long ans = 0;
	while(s[p] >= '0' && s[p] <= '9' ){
		ans = ans * 10 + s[p] - '0';
		ans %= P;
		p++;
	}
	return ans;
}
int main(){
	while( getline(cin,s) && s[0] != '0' ){
		int pos = s.find(":");
		string a = s.substr(0,pos);
		string b = s.substr(pos+1);
		b.erase(remove(b.begin(),b.end(),' '),b.end());
		b.erase(remove(b.begin(),b.end(),'\r'),b.end());
		
		s = b + "~";
		P = atoi(a.c_str());
		p = 0;
		try{
			long long r = A();
			cout << b << " = " << r << " (mod " << P << ")" << endl;
		}catch(const char *a){
			cout << "NG" << endl;
		}
			
	}
}

Measured memory_bytes: 1604
<?php
fscanf(STDIN, '%d %d', $n, $l);
$taste = [];
$cond = false;
for($i = 1; $i <= $n; $i++) {
    $taste_i = $l + $i - 1;
    $taste[] = $taste_i;
    $abs_taste[] = abs($taste_i);
    if($taste_i <= 0) $cond = true;
}
//var_dump($cond);
asort($taste);
asort($abs_taste);
//var_dump($taste, $abs_taste); echo PHP_EOL;
// incl. value <= 0
if($cond) {
    $key = 0; $index = 0;
    if(in_array(0, $abs_taste)) {
        $index = 0;
    } else {
        $index = min($abs_taste);
    }
    $key = array_search($index, $abs_taste);
//    var_dump($key);
    unset($taste[$key]);
} else {
    $taste = array_slice($taste, 1);
}
//var_dump($taste, $abs_taste);
echo array_sum($taste), PHP_EOL;

Measured memory_bytes: 4728
#include<iostream>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;

int main(){
	int n,q,t;
	string name;
	queue<pair<string,int> > p;
	cin>>n>>q;
	while(n--){
        cin>>name>>t;
        p.push(make_pair(name,t));
    }

    pair<string,int> u;
    int elaps=0;
    int a=0;
    while(!p.empty()){
    	u=p.front();p.pop();
        a=min(q,u.second);
        u.second-=a;
        elaps+=a;
        if(u.second>0)
        	p.push(u);
        else{
        	cout<<u.first<<' '<<elaps<<endl;
        }
    }
    

}


Measured memory_bytes: 6236
//e4-e5-f4
//#include <boost/multiprecision/cpp_int.hpp> 
#include "bits/stdc++.h"
//#include "ext/pb_ds/assoc_container.hpp"
//#include "ext/pb_ds/tree_policy.hpp"
typedef long long int ll;
typedef double db;
// __int128 s128;
// __uint128_t u128;
typedef unsigned long long u64;
#define int long long int
#define PI 3.14159265359
#define sz(a) (ll)a.size()
#define lt(a) (ll)a.length()
#define pll pair<ll,ll>
#define tc(x) ll x; cin>>x; while(x--)
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define bac(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define print(a)  for (auto x : a) cout << x << " "; cout << endl
#define sl set<ll>
#define usl unordered_set<ll>
#define mll map<ll,ll>
#define umll unordered_map<ll,ll>
#define vl vector<ll>
#define vpl vector<pll>
#define vvl vector<vector<ll>>
#define mt make_tuple
#define eb emplace_back
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define setbits(a) __builtin_popcountll(a)
#define ps(x,y) fixed<<setprecision(y)<<x;
#define F first
#define S second
#define teevra_gati ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define P 1000000007
#define Q 1000000006
#define inf 1e18
#define N 50
#define M 105
//using namespace boost::multiprecision; 
//using namespace __gnu_pbds;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //shuffle(all(v), rng);

void solve(){
    ll n;
    string s;
    cin>>n>>s;
    ll dp[n+1][n+1] = {}, pre[n+1][n+1] = {};
    dp[0][1]=1;
    f(j,1,n+1) pre[0][j] = 1;
    f(i,1,n){
        f(j,1,i+2){
            //dp[i][j] = number of permutations of 1...(i+1), with last element as j
            if(s[i-1]=='<') dp[i][j] = pre[i-1][j-1];
            else dp[i][j] = (pre[i-1][i] - pre[i-1][j-1] + 2*P) % P;
        }
        f(j,1,n+1) pre[i][j] = (pre[i][j-1] + dp[i][j]) % P;
    }
    ll ans = 0;
    f(j,1,n+1) (ans += dp[n-1][j]) %= P;    
    cout<<ans;
}

signed main() {
    teevra_gati
    
    solve();

    return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  int x;
  cin >> x;
  int s = x;
  int mx = x;
  for (int i = 0; i < n - 1; i++) {
    cin >> x;
    s += x;
    mx = max(mx, x);
  }
  if (mx >= s - mx) {
    cout << "No";
  } else {
    cout << "Yes";
  }
  return 0;
}


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

int main() {
  vector<vector<int>> v(9, vector<int>(9));
  for (int i = 0; i < 9; i++) {
    for (int j = 0; j < 9; j++) {
      v.at(i).at(j) = (i + 1) * (j + 1);
    }
  }
  
  int n;
  cin >> n;
  bool b = false;
  for (int i = 0; i < 9; i++) {
    for (int j = 0; j < 9; j++) {
      if (n == v.at(i).at(j)) b = true;
    }
  }
  
  if (b) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
n = int(input())
x = list(map(int, input().split()))
max_val = 0
result = 100000000
for i in range(n):
    s1 = sum(x[:i+1])
    s2 = sum(x[i+1:])
    if result > abs(s1-s2):
        result = abs(s1-s2)
print(result)

Measured memory_bytes: 3060
#include<stdio.h>
#define M 100000

int parent(int i){
  return i/2;
}
int left(int j){
  return 2*j;
}
int right(int k){
  return 2*k+1;
}

int main(){
  int N,i,st[M+1];

  scanf("%d",&N);
  for(i=1;i<=N;i++){
    scanf("%d",&st[i]);
  }
  for(i=1;i<=N;i++){
    printf("node %d: key = %d,",i,st[i]);
    if(parent(i)>=1)printf(" parent key = %d,",st[parent(i)]);
    if(left(i)<=N)printf(" left key = %d,",st[left(i)]);
    if(right(i)<=N)printf(" right key = %d,",st[right(i)]);
    printf(" \n");
  }
		     
  return 0;
}






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

bool dp[81][81][160*80+1];

int main(){
    // 入力処理
    int h,w; cin >> h >> w;
    int a[h][w], b[h][w];
    rep(i,h) rep(j,w) cin >> a[i][j];
    rep(i,h) rep(j,w) cin >> b[i][j];

    // dp準備
    dp[0][0][abs(a[0][0] - b[0][0])] = true;
    // 上端の処理
    rep(i,w-1){
        int ta = a[0][i+1], tb = b[0][i+1];
        for(int k = 0; k + abs(ta - tb) <= (h+w)*80; ++k){    
            dp[0][i+1][k] |= dp[0][i][abs(k - abs(ta - tb))];
            dp[0][i+1][k] |= dp[0][i][k + abs(ta - tb)];
        }
    }
    // 左端の処理
    rep(i,h-1){
        int ta = a[i+1][0], tb = b[i+1][0];
        for(int k = 0; k + abs(ta - tb) <= (h+w)*80; ++k){    
            dp[i+1][0][k] |= dp[i][0][abs(k - abs(ta - tb))];    
            dp[i+1][0][k] |= dp[i][0][k + abs(ta - tb)];
        }
    }

    // dp計算
    for(int i = 1; i < h; ++i) for(int j = 1; j < w; ++j){
        int ta = a[i][j], tb = b[i][j];
        for(int k = 0; k + abs(ta - tb) <= (h+w)*80; ++k){    
            dp[i][j][k] |= dp[i-1][j][abs(k - abs(ta - tb))];
            dp[i][j][k] |= dp[i][j-1][abs(k - abs(ta - tb))];
            dp[i][j][k] |= dp[i-1][j][k + abs(ta - tb)];
            dp[i][j][k] |= dp[i][j-1][k + abs(ta - tb)];
        }
    }

    // 出力
    rep(k, (h+w)*80+1){
        if(dp[h-1][w-1][k]){
            cout << k << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 82176
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
v1 = v[::2]
v2 = v[1::2]

C1 = Counter(v1)
C2 = Counter(v2)
#print(C1.most_common(1))
#print(C2.most_common(1))
#print(C1.most_common(1)[0][0]!=C2.most_common(1)[0][0])
if C1.most_common(1)[0][0]!=C2.most_common(1)[0][0]: 
  print((n//2-C1.most_common(1)[0][1])+(n//2-C2.most_common(1)[0][1]))
  exit()
  
elif C1.most_common(1)[0][1]==C2.most_common(1)[0][1]==n//2:
  print(n//2)
  exit()
  
elif C1.most_common(1)==C2.most_common(1) and C1.most_common(2)[1][1] >= C2.most_common(2)[1][1]:
  print((n//2-C1.most_common(2)[1][1])+(n//2-C2.most_common(1)[0][1]))
  exit()

else:
  print((n//2-C1.most_common(1)[0][1])+(n//2-C2.most_common(2)[1][1]))
  exit()

Measured memory_bytes: 64900
def main():
    ans_list = []

    while True:
        ans = solve()
        if ans == -1:
            break
        ans_list += ans

    for ans in ans_list:
        print(ans)

def solve():
    res_list = []
    N,M = map(int,input().split())
    if (N,M) == (0,0):
        return -1
    sh = [[0]*(1260-540+1) for _ in range(M)]
    r = int(input())
    for _ in range(r):
        t,n,m,s = map(int,input().split())
        t -= 540
        m -= 1
        if s == 1:
            sh[m][t] += 1
        elif s == 0:
            sh[m][t] -= 1
    acc = 0
    for i,line in enumerate(sh):
        for j,bit in enumerate(line):
            acc += bit
            if acc >= 1:
                sh[i][j] = 1
            else:
                sh[i][j] = 0
    q = int(input())
    for _ in range(q):
        ts,te,m = map(int,input().split())
        ts -= 540
        te -= 540
        m -= 1
        res = sum(sh[m][ts:te])
        res_list.append(res)
    return res_list
    
main()


Measured memory_bytes: 60984
package main

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

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func warshallFloyd(n int, d [][]int) {
	for k := 0; k < n; k++ {
		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j])
			}
		}
	}
}

func main() {
	H := readInt()
	W := readInt()

	S := make([]string, H)
	for i := 0; i < H; i++ {
		S[i] = readString()
	}

	n := H * W
	d := make([][]int, n)
	for i := 0; i < n; i++ {
		d[i] = make([]int, n)
		fillInts(d[i], math.MaxInt32)
		d[i][i] = 0
	}

	for y := 0; y < H; y++ {
		for x := 0; x < W; x++ {
			if S[y][x] == '#' {
				continue
			}
			if y-1 >= 0 && S[y-1][x] != '#' {
				d[y*W+x][(y-1)*W+x] = 1
			}
			if y+1 < H && S[y+1][x] != '#' {
				d[y*W+x][(y+1)*W+x] = 1
			}
			if x-1 >= 0 && S[y][x-1] != '#' {
				d[y*W+x][y*W+x-1] = 1
			}
			if x+1 < W && S[y][x+1] != '#' {
				d[y*W+x][y*W+x+1] = 1
			}
		}
	}

	warshallFloyd(n, d)

	result := 0
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if d[i][j] < math.MaxInt32 && d[i][j] > result {
				result = d[i][j]
			}
		}
	}

	fmt.Println(result)
}

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
}

func fillInts(a []int, x int) {
	for i := 0; i < len(a); i++ {
		a[i] = x
	}
}


Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main()
{
  ll n,k;
  map<int,ll> mp;
  cin>>n>>k;
  rep(i,n)
  {
    int a,b;
    cin>>a>>b;
     //まだ無かったらmapに追加
     if(mp.find(a)==mp.end()) mp[a]=b;
     //すでにmapにあったら増やす
     else mp[a]+=b;
  }
  ll i=1;
  while(k>0)
  {
    k-=mp[i];
    i++;
  }

  cout<<i-1<<endl;
}


Measured memory_bytes: 6528
#include<iostream>
using namespace std;
int main()
{
	int n,sum;
	int a[3000];
	while(cin>>n)
	{
		sum=0;
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=0;i<n;i++)sum+=a[i];
		cout<<sum-n<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
const int INF = 100000000;
typedef pair<int, int> P;
const int MAX_N = 1000000;
typedef int64_t ll;

ll A, B, C, K;

int main() {
	cin >> A >> B >> C >> K;
	if (K%2==1)
	{
		cout << B - A << endl;
	}
	else {
		cout << A - B << endl;
	}
}

Measured memory_bytes: 3628