akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    string s;cin >> s;
    string s2;cin >> s2;
    int count = 0;
    rep(i,3){
        if(s[i] == s2[i])count++;
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    string S;
    cin >> S;
    ll K;
    cin >> K;

    char ans;
    for (int i = 0; i < K; i++)
    {
        if (S[i] == '1' && K == i + 1)
        {
            ans = '1';
        }
        else
        {
            if (S[i] != '1')
            {
                ans = S[i];
                break;
            }
        }
    }

    // if (S[0] == '1')
    // {
    //     if (K == 1)
    //     {
    //         ans = '1';
    //     }
    //     else
    //     {
    //         ans = S[1];
    //     }
    // }
    // else
    // {
    //     ans = S[0];
    // }
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod=1e9+7;
ll dp[1005][1005],n,m;
string a[1005];
ll solve(ll i,ll j){
if(i>=n || j>=m)return 0;
if(i==n-1 && j==m-1)return 1;
ll ans=0;
if(dp[i][j]!=-1)return dp[i][j];
if(a[i+1][j]=='.')ans+=solve(i+1,j);
if(a[i][j+1]=='.')ans+=solve(i,j+1);
return dp[i][j]=ans%mod;
}
int main(){
    cin>>n>>m;
    for(ll i=0;i<n;i++)cin>>a[i];
    for(ll i=0;i<1005;i++)for(ll j=0;j<1005;j++)dp[i][j]=-1;
    //for(ll i=0;i<n;i++)cout<<a[i]<<endl;
    cout<<solve(0ll,0ll)<<endl;

return 0;
}


Measured memory_bytes: 9344
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;

const int MAX_H=500,MAX_W=500;
typedef long long ll;
int H,W,h,w;

ll ans[MAX_H][MAX_W];

int main(){
	cin>>H>>W>>h>>w;
	if (H%h==0 && W%w==0){
		cout<<"No"<<endl;
	}else{
		ll x=(H/h)*(W/w)/(H*(W%w)+W*(H%h)-(W%w)*(H%h))+1,y=-(h*w-1)*x-1;
		assert(llabs(x)<=1e9 && llabs(y)<=1e9);
		REP(i,H/h){
			REP(j,W/w){
				REP(a,h){
					REP(b,w){
						ll z;
						if (a==h-1 && b==w-1){
							z=y;
						}else{
							z=x;
						}
						ans[i*h+a][j*w+b]=z;
					}
				}
			}
		}
		REP(i,H){
			REP(j,W){
				if (ans[i][j]==0){
					ans[i][j]=x;
				}
			}
		}
		cout<<"Yes"<<endl;
		REP(i,H){
			REP(j,W){
				if (j)cout<<" ";
				cout<<ans[i][j];
			}
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=1e5,mod=1e9+7;
typedef ll fuko[yuzu|10];
ll n,ans;
fuko a,c,wh,wq;
char str[yuzu|10];

ll kasumi(ll a,ll b){
if (b<0) return 0;
ll s=1;
for (;b;b>>=1,a=a*a%mod) if (b&1) s=s*a%mod;
return s;
}

int main(){
int i,j;
scanf("%s",str+1);
n=strlen(str+1);
for (i=1;i<=n;i++){
  a[i]=a[i-1]+(str[i]=='A');
  wq[i]=wq[i-1]+(str[i]=='?');
  }
for (i=n;i;i--){
  c[i]=c[i+1]+(str[i]=='C');
  wh[i]=wh[i+1]+(str[i]=='?');
  }
for (i=1;i<=n;i++){
  if (str[i]=='B'||str[i]=='?'){
    ans=(ans+(a[i-1]*kasumi(3,wq[i-1])%mod+kasumi(3,wq[i-1]-1)*wq[i-1]%mod)%mod*(c[i+1]*kasumi(3,wh[i+1])%mod+kasumi(3,wh[i+1]-1)*wh[i+1]%mod)%mod)%mod;
    }
  }
write(ans);
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std ;
 
int main()
{
  int n , k , a , answer ;
  cin >> n >> k ;
  for(int i=0; i<n; i++)
  {
    cin >> a ;
    if(a >= k)
      answer++ ;
  }
  cout << answer << endl ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define vii vector<int>
#define Itadakimasu ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define dash   continue;
#define br break;
#define sz size()
#define Tadaima return 0;
#define pb push_back
#define fr first
#define sc second
#define N 100010
#define T ll t;cin>>t;while(t--)
#define all(x) x.begin(),x.end()


using namespace std;

ll dp[N];

int main()
{
    Itadakimasu

    ll n,a[N];
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }

    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(abs(a[i-1]-a[i])+dp[i-1],abs(a[i-2]-a[i])+dp[i-2]);
    }
    cout<<dp[n-1]<<endl;




    Tadaima
}


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

int main(){
  int N, K;
  cin >> N >> K;
  int ans=0;
  for(int i=0; i<N; i++){
    int x;
    cin >> x;
    ans+= min(2*x, 2*(K-x));
  }
  cout << ans << endl;
}

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

int main()
{
	int d1, d2, m1, m2;
	cin >> m1 >> d1 >> m2 >> d2;
	if(d2 == 1 && (m2 - m1 == 1 || (m1 == 12 && m2 == 1)))
	{
		switch(m1)
		{
			case 1: if(d1 == 31) cout << 1; else cout << 0; break;
			case 2: if(d1 == 28 || d1 == 29) cout << 1; else cout << 0; break;
			case 3: if(d1 == 31) cout << 1; else cout << 0; break;
			case 4: if(d1 == 30) cout << 1; else cout << 0; break;
			case 5: if(d1 == 31) cout << 1; else cout << 0; break;
			case 6: if(d1 == 30) cout << 1; else cout << 0; break;
			case 7: if(d1 == 31) cout << 1; else cout << 0; break;
			case 8: if(d1 == 31) cout << 1; else cout << 0; break;
			case 9: if(d1 == 30) cout << 1; else cout << 0; break;
			case 10: if(d1 == 31) cout << 1; else cout << 0; break;
			case 11: if(d1 == 30) cout << 1; else cout << 0; break;
			case 12: if(d1 == 31) cout << 1; else cout << 0; break;
		}
	}
	else cout << 0;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <cmath>
using namespace std;
int a, b, c;
int main() {
    cin >> a >> b >> c;
    int www = b*10+c;
    if(www%4==0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>//sort(all(変数),greater<型名>())で降順に,reverse()で逆に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>
#include<set>
#include<stack>
#include<string>//変数.substr(どこから,何文字)で文字列ゲット
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep(i,n) for(ll i=0; i<n; i++)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  string s,t;  cin >> s >> t;
  int ans = 0;
  rep(i,s.size()){
    if(s[i] == t[i]){
      ans++;
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
import numpy as np

x, k, d= map(int, input().split())

xx=x
kk=k

if (x >=0):
  k_int=int(x/d)
  if (k_int >= k):
    xmin=abs(x-k*d)
  else:
    xx1=x-k_int*d
    xx2=xx1-d
    if ((k-k_int) % 2 == 0): 
      xmin=abs(xx1)
    else: xmin=abs(xx2)

if (x <0):
  k_int=int(abs(x)/d)
  if (k_int >= k):
    xmin=abs(x+k*d)
  else:
    xx1=x+k_int*d
    xx2=xx1+d
    if ((k-k_int) % 2 == 0): 
      xmin=abs(xx1)
    else: xmin=abs(xx2)
      
      
print (xmin)


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

int main(){
    int x, y;
    
    while(true){
        cin >> x >> y;
        if(x == 0 && y == 0) break;
        if(x > y){
            swap(x, y);
        }
        cout << x << " " << y<< endl;
    }
    return 0;
}


Measured memory_bytes: 3016
#include <iostream>
#include <cmath>
#include <vector>

using lint = long long;

void solve() {
    lint x1, y1, x2, y2;
    std::cin >> x1 >> y1 >> x2 >> y2;
    --x1, --y1, --x2, --y2;

    lint ans = std::abs(x2 - x1) + std::abs(y2 - y1);
    lint three = 1;

    for (int i = 0; i < 30; ++i) {
        for (int j = 0; j < 2; ++j) {
            std::swap(x1, y1);
            std::swap(x2, y2);

            if (x1 / three != x2 / three ||
                (x1 / three) % 3 != 1 ||
                std::abs(y1 / three - y2 / three) <= 1) continue;

            lint d1 = x1 % three, d2 = x2 % three;
            lint d = std::min(d1 + d2 + 2, three - d1 + three - d2);
            ans = std::max(ans, d + std::abs(y2 - y1));
        }
        three *= 3;
    }

    std::cout << ans << std::endl;
}

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

    int q;
    std::cin >> q;
    while (q--) solve();

    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
int main(){
    int i,j,k,l[1000];
    char s[100][1000],a;
    for(i=0;i<3;i++)
    {
        scanf("%s",s[i]);
        l[i]=strlen(s[i]);
    }
    if(s[0][l[0]-1]==s[1][0]  && s[1][l[1]-1]==s[2][0])
    {
        printf("YES\n");
    }
    else printf("NO\n");
return 0;
}



Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int n = ni();
        int m = ni();
        int[] c = nia(m);

        int[] dp = new int[n + 1];
        int INF = Integer.MAX_VALUE;
        Arrays.fill(dp, INF);
        dp[0] = 0;

        for (int i = 0; i < m; i++) {
            for (int j = 0; j <= n; j++) {
                if (dp[j] != INF && j + c[i] <= n) {
                    dp[j + c[i]] = Math.min(dp[j + c[i]], dp[j] + 1);
                }
            }
        }

        out.println(dp[n]);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 25192
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
const ll N = 2e5+10;
const ll M=2005;

vector<ll>graph[N];
ll arr[N];


int main(){
    
        #ifdef debug
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout); 
            
        #endif
            ios_base::sync_with_stdio(0);
            cin.tie(0);cout.tie(0);
            
            /*ll T=1;
            while(T--){*/
                ll h=0,n=0,flag=0;
                ll x=0;
                cin>>h>>n;
                for(ll i=0;i<n;i++){
                    cin>>x;
                    flag=flag+x;
                }
                if(flag>=h){
                    cout<<"Yes";
                }
                else{
                    cout<<"No";
                }
            //}
                
            
            
        return 0;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <algorithm>
#include <vector>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int N(4010), M(4000), Mod(924844033);
int n, K, fac[N], len[N], f[N][N][2], cnt, tot;

int main()
{
	n = read(), K = read(), fac[0] = f[0][0][0] = 1;
	for (int i = 1; i <= M; i++) fac[i] = 1ll * fac[i - 1] * i % Mod;
	for (int i = 1; i <= n; i++)
	{
		int p = i + K, q = i - K;
		if (q >= 1 && p <= n) len[p] = len[q] + 2, len[q] = 0;
		else if (q >= 1 && q <= n) ++len[q];
		else if (p >= 1 && p <= n) ++len[p];
	}
	for (int i = 1; i <= n; i++) cnt += len[i], tot += (len[i] + 1) / 2;
	for (int i = 1, cur = 0; i <= n; i++)
	{
		for (int j = cur + 1; j <= cur + len[i]; j++)
			for (int k = 0; k <= tot; k++)
			{
				f[j][k][0] = (f[j - 1][k][1] + f[j - 1][k][0]) % Mod;
				if (k) f[j][k][1] = f[j - 1][k - 1][0];
				if (j == cur + 1 && k) f[j][k][1] = (f[j - 1][k - 1][1] + f[j][k][1]) % Mod;
			}
		cur += len[i];
	}
	int ans = 0;
	for (int i = 0, o = 1; i <= tot; i++, o = Mod - o)
		ans = (ans + 1ll * o * (f[cnt][i][0] + f[cnt][i][1]) % Mod * fac[n - i]) % Mod;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 124544
#include<stdio.h>
#define N 20//the maximum number of first elements 
int solve(int[],int,int,int);
int main(void)
{
  int i;//counter
  int n;//the number of elements that can be used
  int arr[N];//input of second line
  int q;//the number of elements judged
  int x;//input of forth line
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&arr[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++)
    {
      scanf("%d",&x);
      if(solve(arr,n,0,x)==1) printf("yes\n");
      else printf("no\n");
    }
  return 0;
}
int solve(int arr[],int n,int p,int t)//checks whether we can make t by selecting after p-th element (inclusive)
{
  //printf("solve(arr,%d,%d,%d)\n",n,p,t); //debugging
  if(p>=n||t<0) return 0;
  if(t==arr[p]) return 1;
  if(solve(arr,n,p+1,t-arr[p])==1) return 1;
  if(solve(arr,n,p+1,t)==1) return 1;
  return 0;
}



Measured memory_bytes: 2048
void solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <limits.h>
#include <complex>
#include <assert.h>
using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;
typedef complex<ld> Point;

void solve() {
	string S;
	cin >> S;
	int ans = INT_MAX;
	for (int n = 0; n <= S.size() - 3; n++) {
		int a = stoi(S.substr(n,3));
		if (abs(753 - a) < ans)ans = abs(753 - a);
	}
	cout << ans << endl;
	return;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N;
 cin >> N;
 vector<int> L(N);
 for (int i=0;i<N;i++) {
     cin >> L.at(i);
 }
 
 
 int ans =0;
 for (int i=0;i<N-2;i++) {
     
     for (int j=i+1;j<N-1;j++) {
         if(L.at(i)==L.at(j)) {
             continue;
         }
         for (int k=j+1;k<N;k++) {
             vector<int> data(3);
             data.at(0)=L.at(i);
             data.at(1)=L.at(j);
             data.at(2)=L.at(k);
             sort(data.begin(),data.end());
             
             if (L.at(i) == L.at(k) || L.at(j) == L.at(k)) {
                 continue;
             }
             else if (data.at(2) >= data.at(0)+data.at(1) ){
                 continue;
             }
             ans++;
             
             
             
             
         }
         }
         
     }
     cout << ans << endl;
 }
 


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

int main(){
  	int N, K, result = 20000;
  
  	cin >> N >> K;
  
  	for(int i = 0;i <= N; i++){
      	if(result > pow(2, i)+K*(N-i))	result = pow(2,i)+K*(N-i);
      	else if(result < pow(2,i)+K*(N-i))	break;
    }
  
  	cout << result << endl;
  
  	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int dfs(string s, char target)
{
    bool ok = true;
    for(int i = 0; i < s.size(); i++) if(s[i] != target) ok = false;
    if(ok) return 0;
    string t = "";
    for(int i = 0; i < s.size() - 1; i++)
    {
        if(s[i] == target or s[i + 1] == target) t += target;
        else t += s[i];
    }
    return dfs(t, target) + 1;
}
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int ans = INF;
    for(int i = 0; i < s.size(); i++) ans = min(ans, dfs(s, s[i]));
    cout << ans << endl;
    return 0;
}



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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> a(N);
    for (int i=0;i<N;++i) cin >> a[i];
    int ans=-1,p,l,ok;
    for (int i=0;i<N;++i){
        for (int j=i+1;j<N;++j){
            p=a[i]*a[j],l=p%10,ok=1;
            while(p>9){
                p/=10;
                ok&=(l-1==p%10);
                l=p%10;
            }
            if (ok) ans=max(ans,a[i]*a[j]);
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using boost::adaptors::reversed;
using boost::irange;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    ll N;
    cin >> N;
    vector<char> S(N);
    for (auto &&i: irange(0LL, N)){
        cin >> S.at(i);
    }
    vector<ll> hidarimuki(N+1);
    hidarimuki.at(0) = 0;
    for (auto &&i: irange(0LL, N)){
        if (S.at(i) == 'W'){
            hidarimuki.at(i+1) = hidarimuki.at(i) + 1;
        } else {
            hidarimuki.at(i+1) = hidarimuki.at(i);
        }
    }
    vector<ll> migimuki(N+1);
    migimuki.at(N) = 0;
    for (auto &&i: irange(0LL, N) | reversed) {
        if (S.at(i) == 'E'){
            migimuki.at(i) = migimuki.at(i+1) + 1;
        } else {
            migimuki.at(i) = migimuki.at(i+1);
        }
    }
    vector<ll> cost(N);
    for (auto &&i: irange(0LL, N)){
        cost.at(i) = hidarimuki.at(i) + migimuki.at(i+1);
    }
    ll min_cost = *min_element(cost.begin(), cost.end());
    cout << min_cost << endl;
    return 0;
}

Measured memory_bytes: 7552
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, n) for (int i = a; i <= (n); ++i)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

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

    vector<ll> a;
    rep(i, 3 * N) {
       int n; cin >> n;
       a.push_back(n);
    }

    sort(a.begin(), a.end(), greater<ll>());

    ll ans = 0;
    for (int i = 1; i <= 2 * N - 1; i+=2) {
        ans += a[i];
    }

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



Measured memory_bytes: 6384
object Main extends App {
  // N個の値     x1,x2,...xN
  // N個の文字列  u1,u2,...uN
  // Uiは 'JPY' or 'BTC'

  final private val DELIMITER = " "
  final private val BTC = BigDecimal(380000)

  var num: Int = _
  val prices = io.Source.stdin.getLines().zipWithIndex.map {
    case (line, index) if index == 0 =>
      num = line.toInt
      None
    case (line, _) =>
      val lines = line.split(DELIMITER)
      val price = BigDecimal(lines(0))
      val cur = lines(1)
      Option((price, cur))
  }

  val sumYen: BigDecimal = prices.flatten.foldLeft(BigDecimal(0)) { (acc, p) =>
    p._2 match {
      case "JPY" => acc + p._1
      case "BTC" => acc + p._1 * BTC
    }
  }
  println(sumYen)
}

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

int main(){
 string N, M;

  cin >> N >> M ;   
int n, m;
  
  cin >> n >> m ;

  string b;
  cin >> b;

  if (N == b){
    cout << n-1 <<" "<< m<<endl;
  }else if (M == b){
    cout <<n<< " " << m-1 <<endl;
  }

}

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

int main(){
  int N; cin >> N;
  int C = N;
  int sum =0;
  while(C>0){
    sum += C%10;
    C /= 10;
  }
  if(N%sum == 0)
  {cout << "Yes" << endl;}
  else
  {cout << "No" << endl;}
}
    

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <sstream>
#include <deque>

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

using namespace std;

int main() {
    int w, h;
    
    while(cin >> w >> h, w||h) {
        int n, o[40][40];
        int dp[FIELD_SIZE][FIELD_SIZE] = {0};

        // 障害物の初期化
        REP(i, 40) REP(j, 40) o[i][j] = 1;

        cin >> n;

        REP(i, n) {
            int x, y;
            cin >> x >> y;
            o[x][y] = 0;
        }

        // 縦横の縁は必ず1通り(障害物を除く)
        dp[1][1] = 1;

        // 障害物が無ければ上と左のマスを足していく
        // ※上下反転してます
        for ( int y = 1; y <= h; y++ ) {
            for ( int x = 0; x < w; x++ ) {
                if ( y == 1 && x == 0 ) continue; //最初の座標は無視
                if ( o[x+1][y] ) dp[x+1][y] = dp[x][y] + dp[x+1][y-1];
            }
        }

        // REP(i, h+1) {
        //     REP(j, w+1) {
        //         if ( i == h && j == w ) cout << "'" << dp[j][i] << "'";
        //         else cout << dp[j][i] << " ";
        //     }
        //     cout << endl;
        // }
        // cout << endl;

        cout << dp[w][h] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1168
s = input()
a = int(s[:2])
b = int(s[2:])
if 0 < a < 13 and 0 < b < 13:
    print('AMBIGUOUS')
elif 0 < b < 13:
    print('YYMM')
elif 0 < a < 13:
    print('MMYY')
else:
    print('NA')

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 505;
int n, m, q, l, r;
int dp[N][N];
int cnt[N][N];

int main() {
    cin >> n >> m >> q;
    for (int i = 0; i < m; ++i) {
        cin >> l >> r;
        ++cnt[l][r];
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = i; j >= 1; --j) {
            dp[j][i] = cnt[j][i] + dp[j + 1][i] + dp[j][i - 1] - dp[j + 1][i - 1];
        }
    }
    for (int i = 0; i < q; ++i) {
        cin >> l >> r;
        cout << dp[l][r] << endl;
    }
    return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vi vector<ll>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define el printf("\n")
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a+0.5);
ll N=500005;
ll MAX=9223372036854775807;
ll MOD=1000000007;
long double PI =4*atan(1);

int main()
{
    int n; cin >> n; vector <ll> t(n); vector<vector<ll> > V(3,vector<ll>(n));
    for (int i=0;i<n;i++)
    {
        sll(V[0][i]);sll(V[1][i]); sll(V[2][i]);
    }

    t.clear();
    vector <vector<ll> > dp(n,vector<ll> (3,0));
    dp[0][0]=V[0][0];
    dp[0][1]=V[1][0];
    dp[0][2]=V[2][0];
    for (int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+V[0][i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+V[1][i];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+V[2][i];
    }
    cout << max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
    return 0;
}


Measured memory_bytes: 8824
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 100'000;
const int LOGN = 19;

int n, m, k;

void solve(int test) {
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int64 ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      ans += a[i] * a[j];
    }
  }
  cout << ans << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}




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

int main(){
  string s;
  cin>>s;
  for(int i=0;i<=s.size();i++){
    if(i==4){
      cout<<" ";
      continue;
    }
    if(i<=3){
    cout<<s[i];
    }else{
      cout<<s[i-1];
    }
  }
    cout<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
signed main(){
    int h,w;cin>>h>>w;
    int ans=1e16;
    ans=min((h%3?1:0)*w,(w%3?1:0)*h);
    rep(i,1,h){
        int a=i*w;
        int b=(h-i)*(w/2);
        int c=(h-i)*(w-(w/2));
        int p=max({a,b,c})-min({a,b,c});ans=min(ans,p);
    }
    rep(i,1,w){
        int a=i*h;
        int b=(w-i)*(h/2);
        int c=(w-i)*(h-(h/2));
        int p=max({a,b,c})-min({a,b,c});ans=min(ans,p);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll num[100005]={0};
ll rsum[100005]={0},gsum[100005]={0};
int main(){
  ll n,q;
  cin>>n>>q;
  for(int i=n-1;i>=0;i--) cin>>num[i];
  for(int i=0;i<n;i++){
    if(i==0) rsum[i]=num[i];
    else rsum[i]=rsum[i-1]+num[i];
  }
  for(int i=0;i<n;i+=2){
    if(i==0) gsum[i]=num[i];
    else gsum[i]=gsum[i-2]+num[i];
  }
  for(int i=1;i<n;i+=2){
    gsum[i]=gsum[i-1];
  }
//  for(int i=0;i<n;i++) cout<<rsum[i]<<" "<<gsum[i]<<endl;
  vector<ll> border,ans;
  if(n%2==1){
    ans.push_back(rsum[n/2]);
    border.push_back(0);
  }
  for(int i=n/2;i>0;i--){
    border.push_back((num[i]+num[2*i])/2+1);
    ans.push_back(rsum[i-1]+gsum[n-1]-gsum[2*i-1]);
  }
//  for(int i=0;i<ans.size();i++) cout<<border[i]<<" "<<ans[i]<<endl;
  for(int i=0;i<q;i++){
    ll kn;
    cin>>kn;
    ll pos=upper_bound(border.begin(),border.end(),kn)-border.begin();
    if(pos==0) cout<<rsum[(n-1)/2]<<endl;
    else cout<<ans[pos-1]<<endl;
  }
}


Measured memory_bytes: 5108
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <fstream>
#include <bitset>
#include <cstdio>
#include <sstream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <cctype>
#include <iomanip>
#include <list>
#include <cstring>

#define INF 2000000000
#define ull unsigned long long int
#define vi vector<int>
#define vii vector<ii>

#define UNVISITED 0
#define OPENED 1
#define CLOSED 2

#define PI 3.14159


using namespace std;

int main () {
    int n;
   scanf("%d", &n);

   long long int sum = n*(n+1)/2;

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 764
use proconio::marker::Chars;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        k: usize,
        c: [ Chars; h],
    }

    let mut ans = 0;
    for mask_i in 0..1 << h {
        for mask_j in 0..1 << w {
            let mut n = 0;
            for i in 0..h {
                for j in 0..w {
                    if (mask_i >> i) & 1 == 0 && (mask_j >> j) & 1 == 0 && c[i][j] == '#' {
                        n += 1;
                    }
                }
            }
            if n == k {
                ans += 1;
            }
        }
    }

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


Measured memory_bytes: 2180
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.ABC118
{
    class D
    {
        public static void Solve()
        {
            var s = Console.ReadLine().Split();
            var a = Console.ReadLine().Split()
                .Select(x => int.Parse(x)-1)
                .OrderByDescending(x => x)
                .ToArray();
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);
            int[] dp = new int[n+1];
            int[] cost = { 2, 5, 5, 4, 5, 6, 3, 7, 6,int.MaxValue,int.MaxValue };

            for (int i = 0; i < m; i++)
            {
                var nc = n - cost[a[i]];
                if (nc < 0)
                    continue;
                dp[nc] = 1;
            }

            for(int i = n; 1 < i; i--)
            {
                if (dp[i] <= 0)
                    continue;

                for(int j = 0; j < m; j++)
                {
                    var nc = i - cost[a[j]];
                    if (nc < 0)
                        continue;
                    dp[nc] = dp[i] + 1;
                }
            }
            //Console.WriteLine(dp[0]);

            var c = 0;
            while (c < n)
            {
                for(int i = 0; i < m; i++)
                {
                    int nc = c + cost[a[i]];
                    if (nc <= n && dp[c] == dp[nc]+1)
                    {
                        if (dp[c] == 1 && nc != n)
                            continue;

                        Console.Write(a[i] + 1);
                        c = nc;
                        break;
                    }
                }
            }
            Console.Write('\n');
        }
    }
}
namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC118.D.Solve();
        }
    }
}


Measured memory_bytes: 13396
#include<cstdio>
#include<cstring>

int main(){

	char s[201], t[101], p[101];

	scanf("%s %s", s, p);

	strcpy(t, s);

	strcat(s, t);

	if ( strstr(s, p) == NULL ) printf ( "No\n");

	else printf("Yes\n");

	return 0;

}

Measured memory_bytes: 972
a , b = map(int,input().split())
s = input()
for i in range(a+b+1):
    if 0 <= i <= a-1:
        if s[i] == "-":
            print("No")
            exit()
    elif i == a:
        if s[i] != "-":
            print("No")
            exit()
    elif a+1 <= i:
        if s[i] == "-":
            print("No")
            exit()
print("Yes")

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

#define pii pair<int,int>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define deb(x) cerr<<#x" = "<<x<<nl
#define in() ( { int a ; scanf("%d",&a); a; } )
#define stree mid=(b+e)>>1,l=2*n,r=l+1
const int N=1e5+9;

struct segtree
{
    int t[4*N];
    void build(int n,int b,int e)
    {
        if(b==e){
            t[n]=1e9;
            return;
        }
        int stree;
        build(l,b,mid);
        build(r,mid+1,e);
        t[n]=min(t[l],t[r]);
    }
    void upd(int n,int b,int e,int i,int x)
    {
        if(b>i||e<i) return;
        if(b==e&&b==i){
            t[n]=x;
            return;
        }
        int stree;
        upd(l,b,mid,i,x);
        upd(r,mid+1,e,i,x);
        t[n]=min(t[l],t[r]);
    }
    int query(int n,int b,int e,int i,int j)
    {
        if(b>j||e<i) return 1e9;
        if(b>=i&&e<=j) return t[n];
        int stree;
        int a=query(l,b,mid,i,j);
        int p=query(r,mid+1,e,i,j);
        return min(a,p);
    }
}t;

int nxt[N];
int32_t main()
{
    int n=in(),m=in();
    char ch[n+1];
    scanf("%s",ch);
    string s=ch;
    t.build(1,1,n);
    t.upd(1,1,n,n,0);
    for(int i=n-1;i>=0;i--){
        if(s[i]=='0'){
            int l=i+1, r=min(n,i+m);
            int ans=t.query(1,1,n,l,r)+1;
            int nw=0;
            while(l<=r){
                int mid=(l+r)/2;
                if(t.query(1,1,n,l,mid)+1==ans) nw=mid,r=mid-1;
                else l=mid+1;
            }
            nxt[i]=nw;
            //cout<<i<<' '<<ans<<' '<<nw<<nl;
            t.upd(1,1,n,i,min((int)1e9,ans));
        }
    }
    int ans=t.query(1,1,n,1,min(n,m));
    if(ans==1e9) puts("-1");
    else{
        printf("%d",nxt[0]);
        int pre=nxt[0];
        for(int i=nxt[pre];pre<n;i=nxt[i]){
            printf(" %d",i-pre);
            pre=i;
        }
        puts("");
    }
    return 0;
}


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

// Cardのイコール演算子をオーバーライドする
struct Card {
  char suit;
  int value;

  bool operator==(const Card &other) {
    if ((suit == other.suit) && (value == other.value)) return true;
    else return false;
  }
  bool operator<(const Card &other) {
    if (value < other.value) return true;
    else return false;
  }
};

void bubbleSort(Card A[], int N) {
  int flag = 1;
  int counter = 0;
  int i = 0;
  while (flag) {
    flag = 0;
    for (int j=N-1; j>i; j--) {
      if (A[j] < A[j-1]) {
        swap(A[j], A[j-1]);
        flag = 1;
        counter += 1;
      }
    }
    i++;
  }
}

void selectionSort(Card A[], int N) {
  int counter = 0;
  for (int i=0; i<N; i++) {
    int minj = i;
    for (int j=i; j<N; j++) {
      if (A[j]<A[minj]) {
        minj = j;
      }
    }
    swap(A[i], A[minj]);
    if (i != minj) counter++;
  }
}

bool isStable(Card in[], Card out[], int N) {
  // in: sort前
  // out: sort後
  for (int i_in=0; i_in<N; i_in++) {
    // i_inに対応するi_outを探す
    int i_out;
    for (int j=0; j<N; j++) {
      if (in[i_in] == out[j]) {
        i_out = j;
        break;
      }
    }
    // i_outをもとに総当り, j_inはvalueがイコールじゃないとだめ
    for (int j_in=0; j_in<N; j_in++) {
      // j_inに対応するj_outを探す
      if ((i_in == j_in) || (in[i_in].value != in[j_in].value)) continue;
      else {
        int j_out;
        for (int j = 0; j < N; j++) {
          if (in[j_in] == out[j]) {
            j_out = j;
            break;
          }
        }
        if (!((i_in<j_in && i_out<j_out) || (i_in>j_in && i_out>j_out))) return false;
      }
    }
  }
  return true;
}

void print(Card in[], Card out[], int N) {
  for (int i=0; i<N; i++) {
    if (i > 0) cout << " ";
    cout << out[i].suit << out[i].value;
  }
  cout << endl;
  if (isStable(in, out, N)) cout << "Stable" << endl;
  else cout << "Not stable" << endl;
}

int main() {
  int N;
  Card A[100], B[100], C[100];
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> A[i].suit >> A[i].value; 
    B[i] = A[i];
    C[i] = A[i];
    // cout << A << endl << B << endl << C << endl;
  }
  bubbleSort(A, N);
  selectionSort(B, N);

  print(C, A, N);
  print(C, B, N);
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pi;
 
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i=a;i<=b;i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define MOD (ll)(1000000007)

void solve()
{
    ll n, k;
    cin >> n >> k;
    n++;

    ll sum = 0;
    ll mx = 0, mi = 0;

    FOR(i, 1, n){
        mx += (n-i);
        mi += i-1;

        if(k<=i){
            sum += (mx-mi+1)%MOD;
            sum %= MOD;
        }
    }
    cout << sum;

    return;
}

int main() 
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fastio

    ll t = 1;
    // cin >> t;

    FOR(i, 1, t){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3652
//We are still young.
// C.cpp
// Created on 2019-02-16 19:54
#include <bits/stdc++.h>
#define LL long long
#define db double
using namespace std;

#define MAXN 100100
#define MAXE 400400

typedef pair<int, int> pii;
#define X first
#define Y second
const int INF = 0x7FFFFFFF;
#define Debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> inline void read(T &x) {
    int ch = getchar();
    bool fg = false;
    for (x = 0; !isdigit(ch); ch = getchar()) {
        if (ch == '-') {
            fg = true;
        }
    }
    for (; isdigit(ch); ch = getchar()) {
        x = x * 10 + ch - '0';
    }
    if (fg) {
        x = -x;
    }
}

int n, a[MAXN];

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
#endif
	read(n);
	read(a[1]);
	for(int i = 2; i <= n; i++) {
		read(a[i]);
		a[1] = __gcd(a[i], a[1]);
	}
	cout << a[1];
	
#ifdef LOCAL
	Debug("My Time: %.3lfms", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
int main(){
    int a,b,c;
    std::cin >> a >> b >> c;
    if(a+c<=b-c){
        for(int i=a;i<a+c;i++){
            std::cout << i << std::endl;
        }
        for(int i=b-c+1;i<=b;i++){
            std::cout << i << std::endl;
        }
    }else{
        for(int i=a;i<=b;i++){
            std::cout << i << std::endl;
        }
    }
    return 0;
        
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
#define pb(a)    push_back(a)
#define il       inline
#define reg      register
typedef long long ll;
typedef double db;
const int maxn=10000;
const int minn=200000+5;
struct Point
{
    db x,y;
    Point(){}
    Point(db x,db y):x(x),y(y){}
};
struct Seg
{
    Point a,b;
    int c;
    Seg(Point a,Point b,int c):a(a),b(b),c(c){}
    friend bool operator<(Seg p,Seg q){
        if(p.a.y!=q.a.y) return p.a.y<q.a.y;
    	return p.c!=q.c?p.c<q.c:p.a.x<q.a.x;
    }
};
db  x[minn<<2];
int q,lenx,ans,tree[minn<<2];
vector<Seg> ve;
void init()
{
    clr(tree,0);
    ve.clear();
    lenx=0;
    ans=0;
    return ;
}
void  pushpu(int k,int c)
{
    while(k)
    {
        tree[k]+=c;
        k>>=1;
    }
}
void update(int l,int r,int nu,int c,int k)
{
    if(nu==l&&r==nu)
    {
        pushpu(k,c);
        return ;
    }
    int mind=(l+r)/2;
    if(nu<=mind){update(l,mind,nu,c,k<<1);}
    if(nu>mind) {update(mind+1,r,nu,c,k<<1|1);}
    return ;
}
void query(int l,int r,int L,int R,int k)
{
    if(L<=l&&r<=R)
    {
        ans+=tree[k];
        return ;
    }
    int mind=(l+r)/2;
    if(L<=mind){query(l,mind,L,R,k<<1);}
    if(R>mind) {query(mind+1,r,L,R,k<<1|1);}
    return ;
}
int slove()
{
    sort(ve.begin(),ve.end());
    sort(x,x+lenx);
    int res=0;
    for(reg int i=0;i<ve.size();i++)
    {
        if(ve[i].a.x==ve[i].b.x){
            int nu=lower_bound(x,x+lenx,ve[i].a.x)-x+1;
            int c=ve[i].c>2?-1:ve[i].c;
            update(1,lenx,nu,c,1);
        }
        else
        {
            ans=0;
            int l=lower_bound(x,x+lenx,ve[i].a.x)-x+1;
            int r=lower_bound(x,x+lenx,ve[i].b.x)-x+1;
            query(1,lenx,l,r,1);
            res+=ans;
        }
    }
return res;
}
int main()
{
//    freopen("data.txt","r",stdin);
    init();
    scanf("%d",&q);
    Point a,b;
    while(q--)
    {
        scanf("%lf%lf",&a.x,&a.y);
        scanf("%lf%lf",&b.x,&b.y);
        if(a.x>b.x||a.y>b.y){swap(a,b);}
        if(a.x!=b.x)
        {
            x[lenx++]=a.x;x[lenx++]=b.x;
            ve.pb(Seg(a,b,2));
        }
        else
        {
            x[lenx++]=a.x;
            ve.pb(Seg(a,a,1));
            ve.pb(Seg(b,b,3));
        }
    }
    printf("%d\n",slove());
    return 0;
}



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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

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

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

int main(){
    bool flag=false;
    ll ans=0,sum=0;

    int w,a,b;
    cin >>w>>a>>b;

    //cout <<fixed<<setprecision(16)<< << endl;
    cout<<max(0,abs(a-b)-w)<<endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

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


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			int[] as = new int[N];
			
			for(int i = 0; i < N; i++) {
				as[i] = sc.nextInt();
			}
			
			long answer = 0;
			int lower = 0;
			
			for(int a : as) {
				answer += Math.max(0, lower - a);
				lower = Math.max(lower, a);
			}
			
			System.out.println(answer);
			
		}
	}

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

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

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

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

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

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

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

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

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

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

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


Measured memory_bytes: 54860
#include<iostream>

using namespace std;

int main(){
  int W,H,N;
  cin >> W>>H>>N;
  int *x=new int[N];
  int *y=new int[N];
  int *a=new int[N];
  for(int i=0;i<N;i++) cin >> x[i] >> y[i] >> a[i];
  int x_l=0;
  int x_r=W;
  int y_u=H;
  int y_d=0;
  for(int i=0;i<N;i++){
    if(a[i]==1){
      if(x[i]>x_l) x_l=x[i];
    }else if(a[i]==2){
      if(x[i]<x_r) x_r=x[i];
    }else if(a[i]==3){
      if(y[i]>y_d) y_d=y[i];
    }else{
      if(y[i]<y_u) y_u=y[i];
    }
  }
  int dx=x_r-x_l;
  int dy=y_u-y_d;
  if(dx<0) dx=0;
  if(dy<0) dy=0;
  cout<< dx*dy <<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
    ll n,m;
    cin>>n>>m;
    if(n==m)
        cout<<"Yes";
    else
        cout<<"No";
}


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

using namespace std;
     
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define bbp __builtin_popcount
#define al 0x3F3F3F3F
#define sz(x) x.size()
#define sqr(x) ((x) * (x))
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define resize(v) v.resize(unique(all(v)) - v.begin());
//#define int long long

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int mod = (int)1e9 + 7;                                   
const int MAX_N = (int)3e5 + 123;
const int N = 2e6 + 123;                     
const int INF = al;           
const ll INFL = 3e18 + 1;
const double pi = acos(-1.0);
const double eps = 1e-9;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

string s;

inline void boost() {
    ios_base :: sync_with_stdio(NULL);                
    cin.tie(NULL), cout.tie(NULL);                            
}                                  
                                                                    
inline void Solve () {
	boost ();
	cin >> s;
	if (sz(s) == 1) cout << s, exit(0);
	bool check = 0;
	int kek = 0;
	for (int i = 0; i < sz(s); i ++) {
		if (s[i] != '9') check = 1;
		kek += s[i] - '0';
	}
	if (!check) cout << sz(s) * 9, exit(0);
	int sum = 0;
	sum += s[0] - '0' - 1;
	sum += (sz(s) - 1) * 9;
	cout << max(sum, kek);
}                          

int main () {
//	freopen("sparse.in", "r", stdin);	         			                    `
//	freopen("sparse.out", "w", stdout);
   int tt = 1;
	while (tt --) {
   	Solve();
   }
   return 0;
}                                                                                             

Measured memory_bytes: 256