akhauriyash/Code-Regression huggingface dataset:
//
//  main.cpp
//  leetcode
//
//  Created by caokai on 2016/11/23.
//  Copyright © 2016年 caokai. All rights reserved.
//

#include <cstdlib>
#include <algorithm>
#include <list>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;
struct region {
    region (int w, int h): wf(0), hf(0), w(w), h(h){}
    int wf, hf, w, h;
    void change (int i, int xi, int yi) {
        switch (i) {
                case 1:
                wf = wf > xi? wf: xi;
                break;
            case 2:
                w = w < xi? w: xi;
                break;
                case 3:
                hf = hf > yi? hf: yi;
                break;
                case 4:
                h = h < yi? h: yi;
                break;
        }
    }
    int count() {
        int val1 = (w - wf);
        int val2 = ( h - hf);
        val1 = val1 > 0? val1: 0;
        val2 = val2 > 0? val2: 0;
        return val2 * val1;
    }
};
int main(int argc, const char * argv[]) {
    int w, h, n;
    scanf("%d %d %d", &w, &h, &n);
    region test(w, h);
    while( n--) {
        int x, y, z;
        scanf("%d %d %d", &x, &y, &z);
        test.change(z, x, y);
    }
    printf("%d\n", test.count());
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
  int a = 0;
  int b = 0;

  scanf("%d", &a);
  scanf("%d", &b);

  if (a < b) {
    printf("a < b\n");
  } else if (a > b) {
    printf("a > b\n");
  } else {
    printf("a == b\n");
  }

  return 0;
}

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


int main(){
	
    int n;
	cin>>n;
	vector<int>arr(n);
	for(int i=0;i<n-1;i++){
		cin>>arr[i];
	}
	vector<int> count(n+1);
	for(int i=0;i<n-1;i++){
		count[arr[i]] += 1;
	}
	for(int i=1;i<=n;i++){
		cout<<count[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 4772
#include<cstdio>
#include<bitset>
using namespace std;

bitset<50001> pt;

void MakeTable(int n){
  pt.reset();
  pt.set(2);
  
  int i;
  for(i=3;i<=n;i+=2)pt.set(i);
  
  i = 3;
  while(i*i<=n){
    for(int j=3*i;j<=n;j+=2*i)pt.reset(j);
    do{i+=2;}while(!pt[i]);
  }
}

int main(){
  int n,ans;
  MakeTable(50000);

  while(scanf("%d",&n) && n){
    if(n&1){
      if(pt[n-2])printf("1\n");
      else printf("0\n");
    }else{
      ans = 0;
      for(int i=0;i<=n/2;i++)
	if(pt[i] && pt[n-i])ans++;
      printf("%d\n",ans);
    }
  }
}
	

Measured memory_bytes: 764
n,a=map(int,input().split())
x=list(map(int,input().split()))
for i in range(n):
  x[i]-=a
dp=[]
for i in range(n+1):
  dp.append([])
  for i in range(6000):
    dp[-1].append(0)
dp[0][3000]=1
for i in range(n):
  for j in range(6000):
    if j+x[i]<6000 and j+x[i]>=0:
      dp[i+1][j+x[i]]+=dp[i][j]
      dp[i+1][j]+=dp[i][j]
print(dp[n][3000]-1)


Measured memory_bytes: 42716
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int area = a * b;
		int length = (a + b) * 2;
		System.out.println(area + " " + length);
	}
}

Measured memory_bytes: 26036
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    ll n,p;
    cin >> n >> p;
    ll num = 2,ans = 1;
    if(n==1){
            cout << p << endl;
            return 0;
    }
    for(ll num=2;num*num<=p;num++){
        if(p==1)    break;
        ll cnt=0;
        while(p%num==0){
                p/=num;
                cnt++;
        }
        ans*=pow(num,ll(cnt/n));
        
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#define Max zhi5968
typedef long long ll;
using namespace std;

int main ()
{
	ll a,b,c;
	cin>>a>>b>>c;
	cout<<min(a*b,c)<<endl;
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

vector<pll> G[101010];
vector<ll> res(101010);

void dfs(ll now, ll par, ll dist){
	if(dist%2 == 0){
		res[now] = 0;
	}else{
		res[now] = 1;
	}
	REP(i, G[now].size()){
		ll next = G[now][i].first;
		ll weight = G[now][i].second;
		if(next == par) continue;
		dfs(next, now, dist+weight);
	}
	return;
}

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

    ll N;
    cin >> N;
    
    REP(i, N-1){
    	ll u, v, w;
    	cin >> u >> v >> w;
    	u--;v--;
    	G[u].push_back({v, w});
    	G[v].push_back({u, w});
    }

    dfs(0, -1, 0);
    REP(i, N){
    	cout << res[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 11904
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
//#pragma GCC optimize("unroll-loops")

#ifdef __APPLE__
    # include <iostream>
    # include <cmath>
    # include <algorithm>
    # include <stdio.h>
    # include <cstdint>
    # include <cstring>
    # include <string>
    # include <cstdlib>
    # include <vector>
    # include <bitset>
    # include <map>
    # include <queue>
    # include <ctime>
    # include <stack>
    # include <set>
    # include <list>
    # include <random>
    # include <deque>
    # include <functional>
    # include <iomanip>
    # include <sstream>
    # include <fstream>
    # include <complex>
    # include <numeric>
    # include <immintrin.h>
    # include <cassert>
    # include <array>
    # include <tuple>
    # include <unordered_map>
    # include <unordered_set>
    # include <thread>
#else
    # include <bits/stdc++.h>
#endif

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define files(name) name!=""?freopen(name".in","r",stdin),freopen(name".out","w",stdout):0
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define elif else if
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;
#define int long long

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

const int arr=2e5+10;
const int ar=2e3+10;
const ld pi=acos(-1);
const ld eps=1e-10;
const ll md=1e9+7;
const ll inf=1e18+10;

///---program start---///

signed main()
{
    #ifdef __APPLE__
        files("barik");
        freopen("debug.txt","w",stderr);
    #endif

    string s,t;
    cin>>s>>t;
    int ans=0;
    for (int i=0;i<len(s);i++){
        ans+=(s[i]!=t[i]);
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 3916
# ABC C-Tsundoku
import sys
input = sys.stdin.readline

n,m,k = map(int,input().split())
an = list(map(int,input().split()))
bn = list(map(int,input().split()))

suma = [0]
sumb = [0]
a = 0
b = 0
for i in an:
    a += i
    suma.append(a)
for i in bn:
    b += i
    sumb.append(b)

res = [0]
l = m
for j in range(n+1):
    if k-suma[j] < 0:
        break
    while k-suma[j]-sumb[l] < 0 and l > 0:
        l -= 1
    res.append(j+l)
print(max(res))

Measured memory_bytes: 50684
import java.util.Scanner;

/**
 * Created by zhangrunfeng on 2/16/20
 */
public class Main {
    private int N;
    private int[] arr;

    public Main(Scanner sc){
        N = sc.nextInt();
        arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }
    }

    private void printArr() {
        for (int i = 0; i < N-1; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println(arr[N-1]);
    }

    public void bubbleSort() {
        int count = 0;
        for (int endIx = 0; endIx < N; endIx++) {
            boolean flag = true;
            for (int i = N-1; i > endIx; i--) {
                if (arr[i-1] > arr[i]) {
                    flag = false;
                    count++;
                    int tmp = arr[i];
                    arr[i] = arr[i-1];
                    arr[i-1] = tmp;
                }
            }
            if (flag) {
                break;
            }
        }
        printArr();
        System.out.println(count);
    }

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



Measured memory_bytes: 26324
#include <iostream>
using namespace std;
const int me = 1e5;
int a[me], b[me], c[me];

int main() {
	int n;
	cin>>n;
	
	for(int i=0; i<n-1; i++) {
	    cin>>a[i];
	}
	
	int sm = a[n-2];
	for(int i=n-2; i>0; i--) {
	    if(a[i-1]<=a[i]) {
	        sm+=a[i-1];
	    }
	    else {
	        sm+=a[i];
	    }
	}
	sm += a[0];
	
	cout<<sm<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int           long long
#define pb            push_back
#define ppb           pop_back
#define si            set <int>
#define endl          '\n'
#define fr            first
#define sc            second
#define mii           map<int ,int >
#define msi           map<string,int >
#define mis           map<int , string>
#define mci       	  map<char,int>  	
#define rep(i,a,b)    for(int  i=a;i<b;i++)
#define repr(i,a,b)	  for(int i=b-1;i>=a;i--)
#define trav(it,v)	  for(auto it=v.begin();it!=v.end();it++)
#define all(v)        v.begin(),v.end()
#define srt(v)        sort(all(v))
#define pii           pair<int ,int >
#define vi            vector<int >
#define vii           vector<pair<int , int >>
#define vs            vector<string>
#define sz(x)         (int )x.size()
#define M             1000000007
#define bs            binary_search
#define mpr            make_pair
#define sp(n)         setprecision(n)
#define spl           " "
#define arr(a,n)      rep(i,0,n) cin>>a[i]
#define mod           998244353
#define MAXN   		  1000000
#define f(n) for(int i=0;i<n;i++)
using namespace std;



bool sortinrevp(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 

bool sortinrev(const int &a,  
               const int &b) 
{ 
       return (a > b); 
} 

int power(int x, unsigned int y, int p) 
{ 
    int res = 1; 
  
    x = x % p;  
  
    while (y > 0) 
    {
        if (y & 1) 
            res = (res*x) % p; 
  
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int isPrime(int n) 
{ 

    if (n <= 1) 
        return 0; 
  
    for (int i = 2; i < n; i++) 
        if (n % i == 0) 
            return 0; 
  
    return 1; 
} 

set<int> st[26];

void solve()
{
	int n;
	cin>>n;
	int a[n];
	vector<pair<int,int>> v;
	rep(i,0,n)
	{
		cin>>a[i];
		v.pb({a[i],i+1});

	}
	sort(all(v));
	trav(it,v)
	cout<<it->sc<<" ";
	

}


signed main()
{
	ios_base::sync_with_stdio(false);
	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;
	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 3312
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	cout << (n - 1) / 2 << endl;

	return 0;
}

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

int main(){
int N;
  cin>>N;
  vector<int>H(N);
  for(int i=0; i<N; i++){
   cin>>H[i];}
  
  int count=0;
  for(int i=N-1; i>=0; i--){
    bool flag=true;
   for(int j=0; j<i; j++){
    if(H[i]<H[j]){flag=false;}
   }
    if(flag){count++;}
  }

  cout<<count;
}


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

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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef long double ld;

//ある値がvector内の要素に含まれているか否か判定する
int vector_finder(std::vector<int> vec, int number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance(vec.begin(), itr);
    if (index != vec.size()) { // 発見できたとき
        return 1;
    } else { // 発見できなかったとき
        return 0;
    }
}

////////////////////////// let's code! /////////////////////////////

int i, j, k;

///// variables frequent to use /////

int main() {

    long N;
    cin >> N;

    long long count = 0;
    REP(i, N - 2) {
        count += i + 2;
    }
    count += 1;

    if (N == 1) count = 0;
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <algorithm>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
#include <cmath>
#include <stack>
#include <limits>
#include <ctime>

using namespace std;

#define ll long long
#define f0(i,n)for(ll i=0;i<n;i++)
#define f0r(i,n)for(ll i=n-1;i>=0;i--)
#define fc(i,c,n,s)for(ll i=c;i<=n;i+=s)
#define fcr(i,c,n,s)for(ll i=n;i>=c;i-=s)
#define sc(n) static_cast<ll>(n)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef list<ll> LST;
typedef vector<ll> VEC;
typedef map<ll, ll> MAP;

int main() {
	IO;
#ifdef _DEBUG
	ifstream cin("In.txt");
#endif
	ll n, m;
	cin >> n;
	vector<pair<string, ll> > vc(n);
	string st;
	for (int i = 0; i < n; i++) {
		cin >> st;
		cin >> m;
		vc[i] = make_pair(st, m);
	}
	ll ans = 0;
	string fn;
	cin >> fn;
	for (int i = 0; i < n; i++) {
		if (vc[i].first == fn) {
			for (int j = i + 1; j < n; j++) {
				ans += vc[j].second;
			}
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();

		int a = sc.nextInt();
		int b = sc.nextInt();

		String u = sc.next();

		if(u.equals(s)) {
			a--;
		} else {
			b--;
		}

		System.out.println(a + " " + b);
	}
}

Measured memory_bytes: 22740
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
    string s;
    cin >> s;
    int length = s.length();
    if(length%2 != 0){
        cout << "No" << endl;
        return 0;
    }
    int i;
    for(i = 0; i < length; i++){
        if(((i%2==0)&&(s[i]!='h'))||((i%2==1)&&(s[i]!='i'))){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

S=input().strip()

from collections import deque
Q=deque(S)

ANS=0

count=0
while len(Q)>0 and Q[0]==">":
    count+=1
    Q.popleft()

ANS+=count*(count+1)//2
count=0

while len(Q)>0 and Q[-1]=="<":
    count+=1
    Q.pop()

ANS+=count*(count+1)//2

if Q==deque():
    print(ANS)
    sys.exit()

Q=list(Q)

count=1
LIST=[]

for i in range(1,len(Q)):
    if Q[i]==Q[i-1]:
        count+=1
    else:
        LIST.append(count)
        count=1

LIST.append(count)

for i in range(0,len(LIST),2):
    s,t=sorted((LIST[i],LIST[i+1]))

    ANS+=t*(t+1)//2+s*(s-1)//2

print(ANS)


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

int main()
{
    int h, n;
    scanf("%d%d", &h, &n);
    int v[n];
    for(int i = 0; i < n; i++)
        scanf("%d", &v[i]);
    sort(v, v + n);
    int sum = 0;
    for(int i = n - 1; i >= 0; i--)
    {
        sum += v[i];
        if(h - sum <= 0)
        {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <cstdio>
#define ll long long
using namespace std;
int main(){
    double a,b,x;
    cin>>a>>b>>x;
    double y=2*x/(a*a)-b;
    if(y>=0){
        double Y=b-y;
        printf("%.10lf",atan(Y/a)*(180/M_PI));
    }
    else {
        double Z=(2*x)/(a*b);
        printf("%.10lf",90-atan(Z/b)*(180/M_PI));
    }
    
    
}

Measured memory_bytes: 256
n, k = map(int, input().split())
h = [int(input()) for i in range(n)]
l = sorted(h, reverse = True)
ans = l[0] - l[k - 1]
for i in range(1, n - k + 1):
    ans = min(ans, l[i] - l[i + k - 1])
print(ans)

Measured memory_bytes: 8280
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)

    def add(self, i, x=1):
        i += 1
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    def get_sum(self, i):
        i += 1
        x = 0
        while i > 0:
            x += self.data[i]
            i -= i & -i
        return x

    # Return sum for [l, r)
    def get_sum_range(self, l, r):
        return self.get_sum(r - 1) - self.get_sum(l - 1)


def main():
    N = int(readline())
    S = readline().strip()
    Q = int(readline())

    bit = [BIT(N) for _ in range(26)]
    for i, c in enumerate(S):
        bit[ord(c) - ord('a')].add(i)

    S = list(S)
    ans = []

    for _ in range(Q):
        n, a, b = readline().split()
        if n == '1':
            i = int(a) - 1
            if b != S[i]:
                bit[ord(S[i]) - ord('a')].add(i, -1)
                bit[ord(b) - ord('a')].add(i, 1)
                S[i] = b
        else:
            res = 0
            l, r = int(a) - 1, int(b) - 1
            for i in range(26):
                if bit[i].get_sum_range(l, r + 1):
                    res += 1
            ans.append(res)

    print(*ans, sep='\n')

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 203084
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

class agc024a {
public:
    void solve(istream& in, ostream& out) {
        i64 A, B, C;
        i64 K;
        in >> A >> B >> C >> K;
        if (K % 2 == 0) {
            out << A - B << "\n";
        } else {
            out << B - A << "\n";
        }
    }
};

int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	agc024a solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
	//(x1, y1)からへ移動する際の(x2, y2)へのベクトルを求める
	int dx = x2 - x1;
	int dy = y2 - y1;
	int x = x2;
	int y = y2;
	for (int i = 0; i < 2; ++i) {
		//90°の回転行列を2回用いると
		//x3, y3 = x2 - dy, y2 + dx 
		//X4, y4 = x3 - dx, y3 - dy 
		swap(dx, dy);
		dx = -dx;
		x += dx;
		y += dy;
		cout << x << " " << y << endl;
	}
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<queue>
using namespace std;
int main(){
	string str,str1;
	int num,num1,sum,count=0,a,b;
	while(cin>>num>>num1){
		sum=num+num1;
		a=sum;
		b=sum;
		for(;;){
			a/=10;
			count++;
			if(a==0 ){
				break;
			}
		}
		cout<<count<<endl;
		a=0;count=0;sum=0;
	}
}

Measured memory_bytes: 3024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  string S;
  cin >> S;
  
  if (S == "Sunny") {
    cout << "Cloudy" << endl;
  } else if (S == "Cloudy") {
    cout << "Rainy" << endl;
  } else {
    cout << "Sunny" << endl;
  }

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <vector>

using namespace std;

const int maxn = 100010;
const int maxm = 200010;
const int mod = 1e9+7;

typedef long long ll;

struct node {
    int u, v, w;
} T[maxm*2];

struct Edge {
    int v, w, x;
} E[maxm*2];

struct Ele {
    int id; ll d;
    Ele(int id_ = 0, ll d_ = 0) : id(id_), d(d_) {}
};

struct cmp {
    bool operator()(const Ele &a, const Ele &b) {return a.d > b.d;}
};

priority_queue<Ele, vector<Ele>, cmp> q;
int n, m, s1, t1, e, l[maxn], v[maxn];
ll dis1[maxn], dis2[maxn], cnt1[maxn], cnt2[maxn];

void insert(int u, int v, int w) {
    E[e].v = v, E[e].x = l[u], E[e].w = w, l[u] = e++;
}

void dijks1ra(int s,ll dis[],ll cnt[]) {
    for(int i = 1; i <= n; i++) dis[i] = 2e18, cnt[i] = 0;
    memset(v, 0, sizeof(v));
    dis[s] = 0;
    cnt[s] = 1;
    q.push(Ele(s, 0));
    while (!q.empty()) {
        Ele x = q.top(); q.pop();
        if (v[x.id]) continue;
        v[x.id] = 1;
        for(int p = l[x.id]; p >= 0; p = E[p].x) {
            if (x.d+E[p].w < dis[E[p].v]) {
                dis[E[p].v] = x.d + E[p].w;
                cnt[E[p].v] = cnt[x.id];
                q.push(Ele(E[p].v, dis[E[p].v]));
            } else {
                if (x.d+E[p].w == dis[E[p].v]) cnt[E[p].v] = (cnt[E[p].v]+cnt[x.id])%mod;
            }
        }
    }
}

int main() {
    memset(l, -1, sizeof(l));
    scanf("%d%d%d%d", &n, &m, &s1, &t1);
    for(int i = 1; i <= m; i++) {
        int u, v, w;
        scanf("%d%d%d", &u, &v, &w);
        insert(u, v, w); insert(v, u, w);
        T[i].u = u; T[i].v = v; T[i].w = w;
        T[i+m].u = v; T[i+m].v = u; T[i+m].w = w;
    }
    dijks1ra(s1, dis1, cnt1); dijks1ra(t1, dis2, cnt2);
    ll ans = cnt1[t1]*cnt2[s1] % mod;
    for (int i = 1; i <= n; i++) {
        if (dis1[i] == dis2[i] && 2*dis1[i] == dis1[t1]) {
            ll t = cnt1[i] * cnt2[i] % mod; t = t * t % mod;
            ans = ((ans-t)%mod+mod)%mod;
        }
    }
    for (int i = 1; i <= (m<<1); i++) {
        int u = T[i].u, v = T[i].v, w = T[i].w;
        if (dis1[u]*2 < dis1[t1] && dis1[v]*2 > dis1[t1] && dis1[u]+dis2[v]+w == dis1[t1]) {
            ll t = cnt1[u]*cnt2[v] % mod; t = t * t % mod;
            ans = ((ans-t)%mod+mod) % mod;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15216
import functools

import os
import sys

sys.setrecursionlimit(10000)
INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def inpm(line):
    return [inp() for _ in range(line)]


def inpfm(line):
    return [inpf() for _ in range(line)]


def inpsm(line):
    return [inps() for _ in range(line)]


def inlm(line):
    return [inl() for _ in range(line)]


def inlfm(line):
    return [inlf() for _ in range(line)]


def inlsm(line):
    return [inls() for _ in range(line)]


def Yesif(cond):
    print('Yes' if cond else 'No')


def YESIF(cond):
    print('YES' if cond else 'NO')


def yesif(cond):
    print('yes' if cond else 'no')


a, b, c = sorted(inl())
Yesif((a + b == c) )


Measured memory_bytes: 3572
/**
       **********    ************
	  Author : Avi J Patel
	  University : DA-IICT
       **********    ************
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair 
#define mt make_tuple
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define Mod 998244353
#define N 200001
#define large 10000000000000001
#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    if(a.second < b.second) return true; 
    else if(a.ss==b.ss) return a.ff<b.ff;
	else return false;
}
bool sortbyboth(const pair<int,int> &a, const pair<int,int> &b)
{
	if(a.first<b.first) return true;
	else if(a.first==b.first) return a.second<b.second;
	else return false;
} 
int pow(int x, int n, int d) {
    if(x==0)
    {
        return 0;
    }
    long long int result=1;
    long long int x1=(long long int)x;
    long long int n1=(long long int)n;
    long long int d1=(long long int)d;
    x1=x1%d1;
    while(n1>0)
    {
        if(n1&1)
        {
            result=(result*x1)%d1;
        }
        n1=n1>>1;
        x1=(x1*x1)%d1;
    }
    if(x==-1 && n&1)
    {
        return (int)(d1-1);
    }
    else if(x==-1 && !(n&1))
    {
        return 1;
    }
    else if (x==1)
    {
        return 1;
    }
    else if(x<-1)
    {
        return (int)(result+d1);
    }
    else if(x>1)
    {
        return (int)result;
    }
}
int main()
{
	FAST
	int r;
	cin>>r;
	cout<<r*r;
	return 0;
}























Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  int n,i,c=0;
  cin>>n>>s;
  for(i=0;i<n-2;i++)
  {
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
      c++;
  }
  cout<<c;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
n = list(str(N))
if n[len(n)-1] == '2' or n[len(n)-1] == '4' or n[len(n)-1] == '5' or n[len(n)-1] == '7' or n[len(n)-1] == '9':
  print('hon')
elif n[len(n)-1] == '0' or n[len(n)-1] == '1' or n[len(n)-1] == '6' or n[len(n)-1] == '8':
  print('pon')
elif n[len(n)-1] == '3':
  print('bon')

Measured memory_bytes: 9216
using System;



namespace hello_cs

{

    class Program

    {

        static void Main(string[] args)

        {

            var blank = " ";

            var num = Console.ReadLine().Split(blank.ToCharArray());

            var box = new int[]{int.Parse(num[2]), int.Parse(num[0]),int.Parse(num[1])};



            Console.WriteLine(String.Join(" ", box));

        }

    }

}



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

int main()
{
  int N;

  cin >> N;

  bool flag = false;

  for (int i = 1; i <= 9; i++)
  {
    for (int j = 1; j <= 9; j++)
    {
      if (N == i * j)
      {
        flag = true;
        break;
      }
    }
  }

  if (flag)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, M, Q;
int a[62], b[62], c[62], d[62];
int A[12];

int score(){
    int res = 0;

    for(int i=0;i<Q;++i){
        if(A[b[i]] - A[a[i]] == c[i]){
            res += d[i];
        }
    }

    return res;
}

int dfs(int i, int lastValue){
    if(i == N){
        return score();
    }

    int res = 0;

    for(int x=lastValue;x<=M;++x){
        A[i] = x;
        res = std::max(res, dfs(i + 1, x));
    }

    return res;
}

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

  std::cin >> N >> M >> Q;

  for(int i=0;i<Q;++i){
      std::cin >> a[i] >> b[i] >> c[i] >> d[i];
      a[i] -= 1;
      b[i] -= 1;
  }

  int res = dfs(0, 1);
  std::cout << res << std::endl;
}


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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 1007;
const lint linf = 0x3f3f3f3f3f3f3f3f;

struct costflow
{
	static const int _n = _ + _ , _e = 999999;

	int to[_e],ne[_e],he[_n],ecnt;
	lint ev[_e],ec[_e];

	inline void adde(int a,int b,lint c,lint d)
	{
		to[++ecnt]=b,ev[ecnt]=c,ec[ecnt]=d,ne[ecnt]=he[a],he[a]=ecnt;
	}

	inline void addde(int a,int b,lint c,lint d)
	{
		adde(a,b,c,d),adde(b,a,0,-d);
	}

	int dcnt,S,T,pv[_n],pe[_n];
	lint dis[_n];bool ed[_n];

	inline int spfa()
	{
		memset(dis,63,sizeof(lint)*(dcnt+2));
		memset(ed,0,sizeof(bool)*(dcnt+2));

		queue<int> q;
		q.emplace(S),dis[S]=0,ed[S]=1;
		while(!q.empty())
		{
			int a=q.front();q.pop(),ed[a]=0;
			for(int i=he[a];i;i=ne[i])
			{
				if(!ev[i])continue;
				int b=to[i];
				if(dis[b]<=dis[a]+ec[i])continue;
				dis[b]=dis[a]+ec[i],pe[b]=i,pv[b]=a;
				if(!ed[b])q.emplace(b),ed[b]=1;
			}
		}

		return dis[T]<linf;
	}

	inline pair<lint,lint> run(int s,int t)
	{
		S=s,T=t;
		lint sflw=0,scos=0;
		while(spfa())
		{
			lint dlt=linf;
			for(int i=T;i!=S;i=pv[i])dlt=min(dlt,ev[pe[i]]);
			for(int i=T;i!=S;i=pv[i])scos+=dlt*ec[pe[i]],ev[pe[i]]-=dlt,ev[pe[i]^1]+=dlt;
			sflw+=dlt;
		}
		return make_pair(sflw,scos);
	}
	
	costflow()
	{
		memset(he,0,sizeof(he)),ecnt=1;
	}
}f;

int n,nn,xs[_],ys[_],cs[_],xt[_],yt[_],ct[_];

int main()
{
	n=ty(),nn=n+n;
	for(int i=1;i<=n;i++)xs[i]=ty(),ys[i]=ty(),cs[i]=ty();
	for(int i=1;i<=n;i++)xt[i]=ty(),yt[i]=ty(),ct[i]=ty();

	f.dcnt=nn+4;

	int s=++f.dcnt,t=++f.dcnt;

	for(int i=1;i<=n;i++)
	{
		f.addde(s,i,cs[i],0);
		f.addde(i,nn+1,cs[i],-xs[i]-ys[i]);
		f.addde(i,nn+2,cs[i],+xs[i]-ys[i]);
		f.addde(i,nn+3,cs[i],-xs[i]+ys[i]);
		f.addde(i,nn+4,cs[i],+xs[i]+ys[i]);
	}

	for(int i=1;i<=n;i++)
	{
		f.addde(n+i,t,ct[i],0);
		f.addde(nn+1,i+n,ct[i],+xt[i]+yt[i]);
		f.addde(nn+2,i+n,ct[i],-xt[i]+yt[i]);
		f.addde(nn+3,i+n,ct[i],+xt[i]-yt[i]);
		f.addde(nn+4,i+n,ct[i],-xt[i]-yt[i]);
	}

	auto ans=f.run(s,t);
	printf("%lld\n",-ans.second);

	return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

ll gcd(ll a, ll b)
{
    ll r = a % b;
    if (r == 0)
        return b;
    return gcd(b, r);
}

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

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

    int l[n + 1], r[n + 1];

    l[0] = 0, r[n] = 0;
    l[1] = a[0], r[n - 1] = a[n - 1];
    for (int i = 2; i <= n; i++)
        l[i] = gcd(l[i - 1], a[i - 1]);

    for (int i = n - 2; i >= 0; i--)
        r[i] = gcd(r[i + 1], a[i]);

    int ans = 1;

    rep(i, n + 1)
    {
        if (l[i] == 0)
            ans = max(ans, r[i + 1]);
        else if (r[i + 1] == 0)
            ans = max(ans, l[i]);
        else
            ans = max(ans, (int)gcd(l[i], r[i + 1]));
    }
    OP(ans);

    return 0;
}

Measured memory_bytes: 1408
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long 
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define print_time cerr << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define ull unsigned long long
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
int gcd(int x,int y)
{
   // cout<<x<<' '<<y<<endl;
    if(y==0)
    return x;
    else
    return gcd(y,x%y);
}
int expo(int n,int m,int p)   //modULAR EXPONENTIATION
{
    int r=1;
    n=n%p;
    while(m>0)
    {
    if(m%2)
	r=(r*n)%p;
    n=(n*n)%p;
    m=m/2;
    }
    return r%p;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
 
    // This is checked so that we can skip 
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
 
    for (int i=5; i*i<=n; i=i+6)
    if (n%i == 0 || n%(i+2) == 0)
       return false;
 
    return true;
}
vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r)
	z[i] = min (r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]])
	++z[i];
    if (i + z[i] - 1 > r)
	l = i, r = i + z[i] - 1;
    }
    return z;
}
int n,k;
int a[105];
bool dp[100005][2],vis[100005][2];
bool solve(int x,int p)
{
	if(x==0)
	{
		if(p==1)
			return true;
		return false;
	}
	if(x<0)
	{
		if(p==0)
			return true;
		return false;
	}
	if(vis[x][p])
		return dp[x][p];
	bool ans=false;
	if(p==0)
	{
		for(int i=0;i<n;i++)
		{
			if(x-a[i]>=0)
				ans=ans|solve(x-a[i],1);
		}
	}
	else
	{
		ans=true;
		for(int i=0;i<n;i++)
		{
			if(x-a[i]>=0)
				ans=ans&solve(x-a[i],0);
		}
		
	}
	vis[x][p]=true;
	dp[x][p]=ans;
	return ans;
}
int32_t main()
{
   IOS;
   /*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin); 
   freopen("output.txt","w",stdout);
   #endif
   /********************* Code starts here ***********************/
   cin>>n>>k;
   for(int i=0;i<n;i++)
   {
   	cin>>a[i];
   }
   bool ans=false;
   for(int i=0;i<n;i++)
   {
   	if(k-a[i]>=0)
   		ans=ans|solve(k-a[i],1);
   }
   if(ans)
   	cout<<"First"<<endl;
   else
   	cout<<"Second"<<endl;
}        


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int n, k;
    cin >> n >> k;
    if (k == 1) cout << 0 << endl;
    else cout << (n-k) << endl;
    return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    ll a, b;
    cin >> a >> b;
    cout << a * b / __gcd(a, b) << endl;
    return 0;
}


Measured memory_bytes: 256
import math

def main():
    A, B, H, M = map(int, input().split())
    rad = math.pi * 2 * (H / 12 + (M / 60)/ 12 - M / 60)
    rsq = (A * A + B * B) - (2 * A * B) * math.cos(rad)
    print(math.sqrt(rsq))
main()  

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

#define ULL unsigned long long
#define LL long long
#define LLD long long double
#define rep(i, n) for(LL i = 0; i < n; i++)

int A, B, C;

void input()
{
  cin >> A >> B >> C;
}

void solve()
{
  cout << min(C, B/A);
}

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

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef unsigned long long ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef pair<int, int> pint;
ll inf = 1000000000 + 7;


vint v1, v2;
int A[505][505];
int S[505][505];

pint req[100001];
int main() {
	ll N, M, Q;
	int L, R, p, q;
	cin >> N >> M >> Q;
	rep(i, M) {
		cin >> L >> R;
		A[L][R] += 1;
	}

	rep(i, 505)
		rep(j, 505) {
		S[i][j + 1] = S[i][j] + A[i][j+1];

	}
	
	int num = 0;

	rep(i, Q) {
		cin >> p >> q;
		req[i].first = p;
		req[i].second = q;

	}



	rep(i, Q) {
		
	  for (int j = req[i].first; j <= req[i].second; j++) {
		  num += S[j][req[i].second] - S[j][req[i].first-1];

	  }

	  cout << num << endl;
	  num = 0;
	}



	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
using namespace std;
int main() {
	int n, ans = 20000;
	cin >> n;
	int p[5000], q[5000];

	for (int i = 0; i < n; i++) {
		cin >> p[i];
		q[i] = p[i];
	}//??\?????¨

	for (int j = 0; j < 4; j++) {
		int counti = 0;//???????????´??§????????????
		for (int i = 0; i < n; i++)
			p[i] = q[i];
		p[0] -= j;//????????????????????????????????????

		for (int i = 0; i < n - 1; i++) {
                        if (p[i] <= 0)
                                    continue;
			counti += p[i] * 2;
			p[i + 1] -= p[i];
		}
		if (p[n - 1] < 0)
			p[n - 1] = 0;
		if (ans > counti + p[n - 1] + j)
			ans = counti + p[n - 1] + j;//a[n-1]?????????????\\??????????????£????????????????????°j??????????????????????????????????????????	
	}
	cout << ans << endl;
}

Measured memory_bytes: 3136
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)


using namespace std;

int64_t f(int64_t i, int64_t k, int64_t n, vector<int64_t>& as)
{
	if (k == 0) return 0;

	int64_t idx = i * 200001LL + k;
	static unordered_map<int64_t, int64_t> msmo;
	auto it = msmo.find(idx);
	if (it != msmo.end()) return it->second;

	int64_t rn = n - i;
	if (rn == k * 2 - 1) {
		int64_t ans = 0;
		do {
			ans += as[i];
			i += 2;
		} while (i < n);
		return ans;
	}

	int64_t ans = max(f(i + 1, k, n, as), f(i + 2, k - 1, n, as) + as[i]);
	msmo[idx] = ans;
	return ans;
}

int64_t dp[200001][3][2];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int64_t n; cin >> n;
	vector<int64_t> as(n); for (auto& a : as) cin >> a;

	dp[0][0][1] = as[0];
	dp[0][1][0] = 0;
	dp[0][0][0] = -10000000000000000;
	dp[0][1][1] = -10000000000000000LL;
	dp[0][2][0] = -10000000000000000LL;
	dp[0][2][1] = -10000000000000000LL;
	FOR_LT(i, 1, n) {
		// take case
		dp[i][0][1] = dp[i - 1][0][0] + as[i];
		dp[i][1][1] = dp[i - 1][1][0] + as[i];
		dp[i][2][1] = dp[i - 1][2][0] + as[i];

		// comp not take
		dp[i][0][0] = dp[i - 1][0][1];
		dp[i][1][0] = max(dp[i - 1][1][1], dp[i - 1][0][0]);
		dp[i][2][0] = max(dp[i - 1][2][1], dp[i - 1][1][0]);
	}

	if (n & 1) {
		cout << max(dp[n - 1][1][0], max(dp[n - 1][2][0], dp[n - 1][2][1])) << endl;
	}
	else {
		cout << max(dp[n - 1][0][0], max(dp[n - 1][1][0], dp[n - 1][1][1])) << endl;
	}

	/*
	int64_t ans = f(0, n / 2, n, as);
	cout << ans << endl;
	*/

	return 0;
}

Measured memory_bytes: 14268
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n;cin>>n;
  int a[100000];
  REP(i,n){
    cin>>a[i];
  }
  sort(a,a+n);
  int low_index;
  int high_index;
  int high=a[n-1];
  REP(i,n){
    if(a[i]>=a[n-1]/2){
      low_index=i;
      break;
    }
  }
  for(int i=n-1;i>=0;i--){
    if(a[i]<=a[n-1]/2){
      high_index=i;
      break;
    }
  }
  if(low_index==high_index){
    cout<<high<<" "<<a[low_index]<<endl;
  }else if((double)a[n-1]/2 -a[high_index] > a[low_index] - (double)a[n-1]/2){
    cout<<high<<" "<<a[low_index]<<endl;
  }else{
    cout<<high<<" "<<a[high_index]<<endl;
  }
  // low_index=lower_bound(a,a+n,high/2) - a;
  // high_index=upper_bound(a,a+n,high/2) - a;
  //
  // if(a[high_index-1] - high/2 <= high/2 - a[low_index]){
  //   cout<<high<<" "<<a[high_index-1]<<endl;
  // }else{
  //   cout<<high<<" "<<a[low_index]<<endl;
  // }
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int x, y;
  cin >> x >> y;

  int ans = x + y / 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
class Position
  def initialize(x = 0, y = 0, count = 0)
    @x = x
    @y = y
    @count = count
  end
  attr_reader :x, :y, :count
  
  def ==(po)
    @x == po.x && @y == po.y
  end
end

h, w = gets.split.map(&:to_i)
ss = h.times.map {gets.chomp}
field = nil

Position.send(:define_method, :succ) do
  x = @x + 1
  y = @y
  if x >= w
    x = 0
    y += 1
    return false if y >= h
  end
  Position.new(x, y)
end

Position.send(:define_method, :move) do |dir|
  x, y = @x, @y
  dx, dy = [[1, 0], [0, -1], [-1, 0], [0, 1]][dir]
  x += dx
  y += dy
  return false if x >= w || x < 0 || y >= h || y < 0
  return false if field[y][x] != "."
  Position.new(x, y, @count + 1).mark
end

Position.send(:define_method, :mark) do
  field[@y][@x] = "*"
  self
end

solve_maze = ->(start) {
  return 0 if ss[start.y][start.x] == "#"
  field = ss.map(&:dup)
  max = 0
  q = [start]
  start.mark
  while (po = q.shift)
    max = po.count if po.count > max
    4.times do |dir|
      nxt = po.move(dir)
      q << nxt if nxt
    end
  end
  max
}


start = Position.new
max = 0
loop do
  tmp = solve_maze.(start)
  max = tmp if tmp > max
  break unless (start = start.succ)
end

puts max

Measured memory_bytes: 1788
import java.util.*;

public class Main {
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
			while(sc.hasNext())
			{
				int a = sc.nextInt();
				int b = sc.nextInt();
				int count = 0;
					for(int i=0; i!=Integer.toString(a+b).length();i++)
					{
						count++;
					}
				System.out.println(count);
			}
	}
}

Measured memory_bytes: 20548
#include<stdio.h>
#include<string.h>

int main(void) {

	int a, b, c, d;

	scanf("%d%d%d", &a, &b, &c);

	d = 100 * a + 10 * b + c;

	if (d % 4 == 0) {
		printf("YES\n");
	}
	else {
		printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef int int__;
#define int long long
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define forn(i, n) for(int i = 0; i < int__(n); i++) 
#define sz(a) int__(a.size())
template<class A>ostream& operator<<(ostream& out,const vector<A>&v){out<<"[";forn(i,sz(v)){if(i)out<<", ";out<<v[i];}return out<<"]";}
const int MAX = 1e9 + 7;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
int Mod(int x){const int mm=998244353;x%=mm;if(x<0)x+=mm;return x;}
int Pow(int x,int n){if(n==0)return 1;int t=Pow(x,n/2);t=Mod(t*t);if(n&1)t=Mod(t*x);return t;}
#define watch(x) cout << #x << " : " << x << endl;
int gcd(int x,int y){return y!=0 ? gcd(y,x%y) : x;}
 
int__ main() {
	fast;
	int n,k; cin >> n >> k;
	vi h(n);
	for(int i=0;i<n;i++) cin >> h[i];
	vi dp(n+k+1,1e12);
	dp[0] = 0;

	for(int i=0;i < n;i++) {
		for(int j=1;j<=k;j++) {
			dp[i+j] = min(dp[i+j], abs(h[i] - h[i+j]) + dp[i]);
		}
	}
	//watch(dp);
	cout << dp[n-1] << endl;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

void solve() {
    ll fact[200001], inv[200001];
    fact[0] = 1;
    rep(i,200000) fact[i + 1] = (fact[i] * (i + 1)) % MOD;
    rep(i,200001) inv[i] = mod_pow(fact[i], MOD - 2, MOD);
    ll H, W, A, B;
    cin >> H >> W >> A >> B;
    ll ans = 0;
    rep(i,H - A) {
        ll x = (fact[i + B - 1] * inv[i]) % MOD;
        x = (x * inv[B - 1]) % MOD;
        x = (x * fact[W - B - 1 + H - 1 - i]) % MOD;
        x = (x * inv[W - B - 1]) % MOD;
        x = (x * inv[H - 1 - i]) % MOD;
        ans = (ans + x) % MOD;
    }
    cout << ans << endl;
    return;
}

int main() {
    solve();
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main() {
    ll h, w;
    cin >> h >> w;
    if(h == 1 || w == 1){
        cout << 1 << endl;
        return 0;
    }
    if (h % 2 == 1 && w % 2 == 1) {
        cout << h * w / 2 + 1 << endl;
    } else {
        cout << h * w / 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256