akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int N;
	cin >> N;
	vector<ll> A(N);
	for (auto& x : A) cin >> x;
	sort(A.rbegin(), A.rend());
	ll res = 0;
	for (int i = 1; i < N; ++ i) {
		res += A[i/2];
	}
	cout << res << endl;
}


Measured memory_bytes: 4832
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
using namespace std;

int main()
{
	int i, j, k, l, m, X, M, flag;
	long long int Q, H, S, D,N;
	long long int ans[3];
	cin >> Q >> H >> S >> D >> N;
	ans[0] = 4 * Q;
	ans[1] = 2 * H;
	ans[2] = S;
	sort(ans, ans + 3);
	if (2 * ans[0] < D) {
		cout << N * ans[0] << endl;
	}
	else {
		if (N % 2 == 0) {
			cout << N / 2 * D << endl;
		}
		else
			cout << N / 2 * D + ans[0] << endl;
	}

	

	return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
  char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
  vector<char*> v({token});
  while(token = strtok(NULL,", ")) v.push_back(token);
  return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
  debug() << " [" << args.back() << ": " << H << "] ";
  args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=1e9+7;
const int MX=0x3f3f3f3f;

int main() {
    IOS;
    string s;
    cin>>s;
    int i,ans=sz(s);
    REP(i,1,sz(s)-1){
    	if(s[i]!=s[i-1]) ans=min(ans,max(i,sz(s)-i));
    }
    cout<<ans;
   	return 0;   
} 

Measured memory_bytes: 3752
#include <iostream>
#include <string>

void solve() {
    std::string s;
    std::cin >> s;

    int sum = 0;
    for (auto c : s) sum += c - '0';
    std::cout << (sum % 9 == 0 ? "Yes" : "No") << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define roop0(n) for(long long i = 0;i < n;i++)
#define roop1(n) for(long long i = 1;i < n;i++)
#define rep(i,a,b) for(long long i = a; i < b; i++)
#define print(a) for(auto x : a) cout << x << " "; cout << "\n"

using namespace std;
using vi   = vector<int>;
using vll  = vector<long long>;
using vs   = vector<string>;
using vvi  = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using vvs  = vector<vector<string>>;

const static string el = "\n";
long long result = 0;

int main () {
  int a,b,c,k; cin >> a >> b >> c >> k;
  roop0(k) {
    if (b <= a) b *= 2;
    else if (c <= b) c *= 2;
  }
  if (a < b && b < c) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) a.begin(),a.end()

bool eval(vector<int> &table,string s,int &i){
    if(isdigit(s[i])) return s[i++] == '1';
    if(s[i] == '-') return !eval(table,s,++i);
    if(isalpha(s[i])) return table[s[i++]-'a'];
    i++; // (
    bool e1 = eval(table,s,i);
    char op = s[i++];
    bool e2 = eval(table,s,i);
    i++; // )
    if(op == '^') return e1^e2;
    if(op == '*') return e1*e2;
    assert(false);
}

int feature(string &E){
    int k = 0;
    int f = 0;
    rep(a,2)rep(b,2)rep(c,2)rep(d,2){
        vector<int> table = {a,b,c,d};
        int i = 0;
        if(eval(table,E,i)){
            f |= 1<<k;
        }
        k++;
    }
    return f;
}

int main(void){
    vector<string> exps[17];
    exps[1] = {"a","b","c","d"};
    for(int m = 2; m <= 16; m++){
        for(string E : exps[m-1]){
            if(E[0] == '-') continue;
            exps[m].push_back("-"+E);
        }
        rep1(x,m-2){
            int y = m-3-x;
            if(x>y) continue;
            for(string E1 : exps[x]){
                for(string E2 : exps[y]){
                    bool ng = false;
                    for(char ch : {'a','b','c','d'}){
                        if(count(all(E1),ch)+count(all(E2),ch)>1){
                            ng = false;
                        }
                    }
                    if(ng) continue;
                    exps[m].push_back("("+E1+"^"+E2+")");
                    exps[m].push_back("("+E1+"*"+E2+")");
                }
            }
        }
    }
    exps[1].push_back("0");
    exps[1].push_back("1");


    vector<int> min_len(1<<16, 20);
    rep1(m,16){
        for(string E : exps[m]){
            int f = feature(E);
            min_len[f] = min(min_len[f], m);
        }
    }

    string E;
    while(cin>>E, E != "."){
        cout<<min_len[feature(E)]<<endl;
    }
    return 0;
}



Measured memory_bytes: 13380
import sys
input = lambda: sys.stdin.readline().rstrip()

n = int(input())
a= [0]*n
b= [0]*n

for i in range(n):
    a[i], b[i] = map(int, input().split())

if n%2 ==1:
    a.sort()
    b.sort()
    xmin= a[int((n-1)/2)]
    xmax= b[int((n - 1) / 2)]

    print(int(xmax-xmin+1))

if n%2 ==0:
    a.sort()
    b.sort()
    xmin = a[int(n/2-1)]+a[int(n/2)]
    xmax = b[int(n / 2 - 1)] + b[int(n / 2)]
    print(int((xmax-xmin)+1))

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

typedef long long ll;

ll GCD(ll a, ll b) {
  return b ? GCD(b, a%b) : a; 
}

int main() {
  int N; cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  
  ll ans = A[0];
  for (int i = 0; i < N; i++) {
    ans = GCD(ans, A[i]);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main(){
	int H, W; cin >> H >> W;
	char c[H][W];
	for(int i = 0; i < H; ++i) for(int j = 0; j < W; ++j) cin >> c[i][j];
	for(int i = 0; i < H; ++i){
		for(int j = 0; j < W; ++j) cout << c[i][j];
		cout << endl;
		for(int j = 0; j < W; ++j) cout << c[i][j];
		cout << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz 100005
#define all(x) x.begin(),x.end()
#define l_b lower_bound
#define u_b upper_bound
#define pb push_back
#define MOD 1000000007
void fastio(void);

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

    int t;  cin>>t;
    if(t<30)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;

    return 0;
}

void fastio(void){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

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

using namespace std;

int main() {
    string str;
    cin >> str;
    vector<long long int> vec;
    long long int cnt=1;
    char cur=str[0];
    for(int i=1; i<str.size(); i++) {
        if(str[i]==cur) {
            cnt++;
        } else {
            vec.push_back(cnt);
            cnt=1;
            cur = str[i];
        }
    }
    vec.push_back(cnt);

    long long int ans=0;
    if(str[0]=='>') {
        ans += (vec[0]+1)*vec[0]/2;
        for(int i=1; i<vec.size()-1; i++) {
            long long int mx=max(vec[i], vec[i+1]), mn=min(vec[i], vec[i+1]);
            ans += (mx+1)*mx/2 + (mn-1)*mn/2;
            i++;
        }
        if(vec.size()%2==0) {
            ans += (vec[vec.size()-1]+1)*vec[vec.size()-1]/2;
        }
    } else {
        for(int i=0; i<vec.size()-1; i++) {
            long long int mx=max(vec[i], vec[i+1]), mn=min(vec[i], vec[i+1]);
            ans += (mx+1)*mx/2 + (mn-1)*mn/2;
            i++;
        }
        if(vec.size()%2) {
            ans += (vec[vec.size()-1]+1)*vec[vec.size()-1]/2;
        }
    }
    cout << ans << endl;


    return 0;
    
}

Measured memory_bytes: 3068
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    vector<ll> len(5, -1);
    for(int i = 1; i < 4; ++i)  cin >> len[i];
    vector<ll> l(n);
    int limit = 1;
    for(int i = 0; i < n; ++i){
        cin >> l[i];
        limit *= 4;
    }

    ll res = 1e+15;
    for(int i = 0; i < limit; ++i){
        int foo = i;
        int id = 0;
        vector<vector<ll>> hoge(4);
        while(foo > 0){
            hoge[foo % 4].push_back(l[id++]);
            foo /= 4;
        }
        if(hoge[1].size() == 0 || hoge[2].size() == 0 || hoge[3].size() == 0)   continue;
        
        ll score = 0;
        for(int s = 1; s < 4; ++s){
            ll sum = accumulate(hoge[s].begin(), hoge[s].end(), 0ll);
            score += 10ll * (hoge[s].size() - 1);
            score += abs(sum - len[s]);
        }
        chmin(res, score);
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	vector<ll>A(N + 1);
	rep(i, N + 1)cin >> A[i];
	vector<ll>B(N);
	rep(i, N)cin >> B[i];
	ll ans = 0;
	rep(i, N) {
		if (B[i] >= A[i]) {
			ans += A[i];
			B[i] -= A[i];
			if (B[i] >= A[i + 1]) {
				ans += A[i + 1];
				A[i + 1] = 0;
			}
			else {
				ans += B[i];
				A[i + 1] -= B[i];
			}
		}
		else {
			ans += B[i];
		}
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1792
n, a, b = map(int, input().split())
mod = 10**9 + 7


def nCr(n,r,mod = 10**9+7):
    r = min(n-r,r)
    numer = denom = 1
    for i in range(1,r+1):
        numer = numer * (n+1-i) %mod
        denom = denom * i % mod
    return numer * pow(denom,mod-2,mod) %mod


ans = (pow(2, n, mod) - nCr(n, a, mod) - nCr(n, b, mod) - 1)%mod
print(ans)

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;

    for (int i = a; i < a*b; i=i+a) {
        if (i % b == c) {
            puts("YES");
            return 0;
        }
    }
    puts("NO");

    return 0;
}

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

int
main(void)
{
    int n, num;
    int i = 0;
    int * arr;

    scanf("%d", &n);
    arr = (int *) malloc(n * sizeof(int));
    while (i < n)
        scanf("%d", arr + i++);
    printf("%d", arr[--n]);
    while (n--)
        printf(" %d", arr[n]);
    putchar('\n');
    free(arr);
    return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define Mid ((l+r)/2)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define drep(i,a,b) for(int i=(a);i>=(b);--i)
#define file(a) freopen(#a".in","r",stdin),freopen(#a".out","w",stdout);
const int maxn=2e5+5,mod=1e9+7,inf=0x3f3f3f3f;
int n,m,Q,K,T;
int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}int a[maxn];
int dsum[maxn];

signed main(){
    //file(a);
    n=read();
    rep(i,1,n)a[i]=read();
    dsum[n]=a[n];
    drep(i,n-1,1)dsum[i]=(dsum[i+1]+a[i])%mod;
    int ans=0;
    rep(i,1,n-1){
        ans=(ans+1ll*a[i]*dsum[i+1]%mod)%mod;
    }printf("%lld\n",ans);


    return 0;
}


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

int main() {
  string number;
  cin >> number;
  
  int a = number[0] - '0';
  int b = number[1] - '0';
  int c = number[2] - '0';
  int d = number[3] - '0';
  
  if(a+b+c+d == 7)      printf("%d+%d+%d+%d=7\n", a, b, c, d);
  else if(a+b+c-d == 7) printf("%d+%d+%d-%d=7\n", a, b, c, d);
  else if(a+b-c+d == 7) printf("%d+%d-%d+%d=7\n", a, b, c, d);
  else if(a+b-c-d == 7) printf("%d+%d-%d-%d=7\n", a, b, c, d);
  else if(a-b+c+d == 7) printf("%d-%d+%d+%d=7\n", a, b, c, d);
  else if(a-b+c-d == 7) printf("%d-%d+%d-%d=7\n", a, b, c, d);
  else if(a-b-c+d == 7) printf("%d-%d-%d+%d=7\n", a, b, c, d);
  else if(a-b-c-d == 7) printf("%d-%d-%d-%d=7\n", a, b, c, d);
  
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()


def main():
    """
    77...7 % K == 0  =>  7 * (10^n - 1) / 9 = K * x (for some x)
                     =>  10^n - 1 = 9 * (K * x) / 7
                     =>  10^n - 1 = L * y (L = 9 * K if K % 7 != 0 else 9 * K / 7)
                     =>  10^n ¥cong 1 (mod L)
    最後の言い換えが出てこなかったです。。。。。。
    Lが2, 5の倍数だと明らかに不適で、そうでない場合はオイラーの定理から
    これを満たすnが¥varphi(L)として書けるので、あとはそこまでを愚直に探索すれば良いと。。。
    """
    K = int(input())
    if K % 2 == 0 or K % 5 == 0:
        print(-1)
        return

    if K % 7 == 0:
        K = K * 9 // 7
    else:
        K *= 9

    n = 1
    power = 10
    while True:
        if power % K == 1:
            print(n)
            return
        else:
            n += 1
            power *= 10
            power %= K

if __name__ == "__main__":
    main()


Measured memory_bytes: 62740
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

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

#define INFTY 2001


//vector<vector<int>> route, mindis;

//void dfs();

int main(){
    int n, x, y;
    cin >> n >> x >> y;
    vector<int> cnt(n, 0);
    x--;
    y--;

    rep(i, n-1){
        rep2(j, i+1, n){
            int a, b;
            a = min(abs(j - i), abs(x - i) + 1 + abs(y - j));
            b = abs(x - j) + 1 + abs(y - i);
            cnt[min(a, b)]++;
        }
    }

    rep2(i, 1, n){
        cout << cnt[i] <<  endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <stdio.h>
 
int main(void) {
    int n, R, ans = INT_MIN, tmp;
    scanf("%d%d", &n, &tmp);
    for (int i = 1; i < n; ++i) {
        scanf("%d", &R);
        if (ans < R - tmp) ans = R - tmp;
        if (R < tmp) tmp = R;
    }
    printf("%d\n", ans);
    return 0;
}


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

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	vector<string> a(h);
	for (int i = 0; i < h; i++)
		cin >> a[i];
	int cnt = 0;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			if (a[i][j] == '#')
				cnt++;
	if (h + w - 1 == cnt)
		cout << "Possible" << endl;
	else
		cout << "Impossible" << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int count = 1;
		while (N >= K) {
			N = N / K;
			count++;
		}
		System.out.println(count);
		return ;
	}
}


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

typedef signed long long ll;
typedef vector <int> vi; 
const int MX = 1e4 + 5;
int dis[MX];
vi G[MX];

int main() {
	ll h, sum = 0, m;
	int n;

	cin >> h >> n;
	for(int i = 0; i < n; i++) {
		cin >> m;
		sum += m;
	}

	if(sum >= h)
		cout << "Yes\n";
	else
		cout << "No\n";
	
    return 0;
}

Measured memory_bytes: 512
n=int(input())
a=sorted(list(map(int,input().split())))
c=1
x=[]
for i in range(n-1):
    if a[i]!=a[i+1]:
        if c>=2:
            x.append(a[i])
        if c>=4:
            x.append(a[i])
        c=1
    else:
        c+=1
if c>=2:
    x.append(a[n-1])
if c>=4:
    x.append(a[n-1])
if len(x)<=1:
    print(0)
else:
    print(x[-1]*x[-2])


Measured memory_bytes: 87780
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>

#define DIV 1000000007
using namespace std;
using ll = long long;

int main(void) {
	int N, K;
	cin >> N >> K;
	
	int mx = (N - 1) * (N - 2) / 2;
	if (K > mx)
		cout << -1 << endl;
	else {
		int rem = mx - K;
		cout << (N - 1) + rem << endl;
		for (int i = 2; i <= N; i++)
			cout << 1 << " " << i << endl;


		for (int i = 2; rem > 0; i++) {
			for (int j = i + 1; j <= N && rem>0; j++) {
				cout << i << " " << j << endl;
				rem--;
			}
		}
	}
}


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

signed main(){
  bool prime;
  int a;
  cin>>a;
  while(1){
    prime=1;
    for(int i=2,j=1;i<=sqrt(a);i+=j,j=2){
      if(!(a%i)){
        prime=0;
        break;
      }
    }
    if(prime){
      cout<<a<<'\n';
      break;
    }
    else a++;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    #define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
    #define ll long long int
    #define ld long double
    #define f(a, b) for (ll i = a; i < b; i++)
    #define in(a, b) (b.find(a) != string::npos)
    #define X first
    #define Y second
    #define vi vector<int>
    #define fill(a, x) memset(a, x, sizeof(a))
    #define pb push_back
    #define pf push_front
    #define mp make_pair
    #define all(v) v.begin(), v.end()
    #define el "\n"
    const ll M = 1e9 + 7;
    using namespace std;

    int main() {
    fio;
    int n,m,c;
    cin>>n>>m>>c;
    int a[m]={0},cnt=0;
    for(int i=0;i<m;i++)cin>>a[i];
    for(int i=0;i<n;i++){
        int b[m]={0};
        int ans=0;
        for(int j=0;j<m;j++){
            cin>>b[j];
            ans+=b[j]*a[j];
        }
        if(ans+c>0)cnt++;
    }
    cout<<cnt<<el;
    return 0;
    }


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

int main(){
  int n;
  cin>>n;
  long long x[n+1];
  for(int i=0;i<n+1;i++){
    cin>>x[i];
  }
  sort(x,x+n+1);
  long long ans=x[1]-x[0];
  for(int i=2;i<n+1;i++){ 
    ans=__gcd(ans,x[i]-x[i-1]);
  }

  cout<<ans<<endl;
  return 0;

}


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

using namespace std;

int main() {
	int n; 
	while (cin >> n, n) {
		vector<int> h(n + 1);
		for (int i = 0; i <= n; ++i) cin >> h[i];
		int ans;
		for (int i = 0; i <= n; ++i) {
			vector<int> tmp(h); tmp.erase(tmp.begin() + i);
			int t = tmp[1] - tmp[0];
			bool flag = true;
			for (int i = 1; i < n; ++i)
				if (t != tmp[i] - tmp[i - 1]) flag = false;
			if (flag) {
				ans = h[i];
				break;
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;
int n, m, ans = 0;
char W[100][100];

void dfs(int y, int x){
    W[y][x] = '#';
    for(int dx = -1; dx <= 1; dx++){
        for(int dy = -1; dy <= 1; dy++){
            if(dx == dy and dx != 0 and dy != 0) continue;
            else if(dx == -dy) continue;
            int nx = dx + x;
            int ny = dy + y;
            if(W[ny][nx] == '.' and 0 <= nx and nx < n and 0 <= ny and ny < m){
                dfs(ny, nx);
                ans++;
            }
        }
    }
    return ;
}

int main(void){
    while(true){
        ans = 0; // 新しいデータセットの度に初期化
        cin >> n >> m;
        if(n == 0 and m == 0) return 0;
        REP(i, m){
            REP(j, n){
                cin >> W[i][j];
            }
        }

        REP(i, m){
            REP(j, n){
                if(W[i][j] == '@'){
                    ans++;
                    dfs(i, j);
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3116
#include <stdio.h> 

int main(){ 

  int a, b, r, tmp; 

  scanf("%d", &a); 


  scanf("%d", &b); 


  if(a<b){ 


    tmp = a; 


    a = b; 


    b = tmp; 


  } 

  r = a % b; 


  while(r!=0){ 


    a = b; 


    b = r; 


    r = a % b; 


  } 

  printf("%d\n", b); 


  return 0; 


} 

Measured memory_bytes: 2692
import scala.annotation.tailrec

object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val t = readLine.trim.toInt
  for (_ ← 0 until t){
    val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
    val boards = readLine.trim.split(' ').map(parseSound)
    val melodies = readLine.trim.split(' ').map(parseSound)
    println(
      if (canMake(boards, melodies)) "Yes"
      else "No"
    )
  }
  def parseSound(str: String): Int = {
    List("C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B").indexOf(str)
  }

  def canMake(boards: Array[Int], melodies: Array[Int]): Boolean = {
    @tailrec
    def sub(position: Int, reversedMelodies: List[Int]): Boolean = {
      reversedMelodies match {
        case Nil if position == -1 ⇒ true
        case Nil ⇒ false
        case _ if !boards.indices.contains(position) ⇒ false
        case h::t if (h + 1) % 12 == boards(position) ⇒ sub(position + 1, t)
        case h::t if h == boards(position) ⇒ sub(position - 1, t)
        case h::t if (h + 11) % 12 == boards(position) ⇒ sub(position - 2, t)
        case _ ⇒ false
      }
    }
    val reversed = melodies.reverse.toList
    sub(boards.length - 1, reversed) || sub(boards.length - 2, reversed)
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


Measured memory_bytes: 428520
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;

int main(){
  int a, b;
  cin >> a >> b;
  if(a > 9 || b > 9){
    cout << -1 << endl;
  }else{
    cout << a*b << endl;
  }
}


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

int dp[maxn];
int a[110];
int n,k;
int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> k;
	rep(i,0,n)
	{
		cin >> a[i];
	} 
	rep(i,1,k+1)
		rep(j,0,n)
			 if (i - a[j] >= 0) dp[i] |= !dp[i - a[j]];

	if (dp[k]) 
		cout << "First" << endl;
    else 
    	cout << "Second" << endl;
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<bitset>
using namespace std;
const int MAXN = 405, MAXM = 100005;
int n, m, ans, x[MAXM], y[MAXM], vis[MAXN];
bitset<MAXN> S[MAXN];

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; ++i) scanf("%d%d", x + i, y + i);
	
	for(int i = 1; i <= n; ++i) {
		S[i].set(i);
		for(int j = m; j >= 1; --j)
		if(S[i][x[j]] && S[i][y[j]]) vis[i] = 1;
		else if(S[i][x[j]]) S[i].set(y[j]);
		else if(S[i][y[j]]) S[i].set(x[j]);
	}
	
	for(int i = 1; i <= n; ++i) if(!vis[i])
	for(int j = i + 1; j <= n; ++j) if(!vis[j])
		if((S[i]&S[j]).none()) ++ans;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
using namespace std;
#define f(n) for(int i=0;i<n;++i)

int main() {
    #define int long long
	int a, b, c;
	cin >> a >> b >> c;
	cout << min(min(a + b, a + c), b + c) << endl;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int digit(int n)
{
    if (n < 10)
    {
        return 1;
    }
    return digit(n / 10) + 1;
}

string int_to_string(int n)
{
    string res = "";
    if (n == 0)
    {
        res = '0';
    }
    while (n)
    {
        char tmp = (n % 10) + '0';
        res = tmp + res;
        n /= 10;
    }
    return res;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> s(m), c(m);
    rep(i, m) cin >> s[i] >> c[i];

    rep(i, 1000)
    {
        if (n != digit(i))
        {
            continue;
        }

        bool flag = true;
        rep(j, m)
        {
            string st_num = int_to_string(i);
            if (st_num[s[j] - 1] != c[j] + '0')
            {
                flag = false;
            }
        }
        if (flag)
        {
            cout << i << '\n';
            return 0;
        }
    }

    cout << -1 << '\n';
    return (0);
}


Measured memory_bytes: 3632
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
	ll n;cin>>n;
	ll ans=0;vi v;
	ll a[n],b[n],cnt=0,s1=0,s2=0,sum=0;
	for(ll i=0;i<n;i++)cin>>a[i];
	for(ll i=0;i<n;i++)cin>>b[i];
	for(ll i=0;i<n;i++){
		s1+=a[i];
		s2+=b[i];
		if(a[i]<b[i]){
			cnt++;
			sum+=b[i]-a[i];
		}
		else if(a[i]>b[i]){
			v.pb(a[i]-b[i]);
		}
	}
	if(s1<s2)return cout<<"-1",0;
	if(v.size()==0||cnt==0)return cout<<"0",0;
	sort(all(v));
	reverse(all(v));
	ll ss=0;
	for(ll i=0;i<v.size();i++){
		if(sum>0){
			if(sum>=v[i]){
				sum-=v[i];
				cnt++;
			}
			else{
				sum=0;
				cnt++;
			}
		}
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 2428
package main

import (
	"fmt"
	"math"
)

func main() {
	var N int
	fmt.Scan(&N)
	n := int(math.Ceil(math.Sqrt(float64(N))))
	var d = []int{}
	for i := 1; i <= n; i++ {
		if N%i == 0 {
			d = append(d, i)
			d = append(d, N/i)
		}
	}
	i := d[len(d)-1]
	j := d[len(d)-2]
	fmt.Println((i - 1) + (j - 1))
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        String s[] = sc.next().split("");
        String t[] = sc.next().split("");
        int count = 0;

        for(int i = 0; i < s.length; i++) {
            if(!s[i].equals(t[i])) {
                count++;
            }
        }

        System.out.println(String.valueOf(count));
    }
}

Measured memory_bytes: 68976
#include "math.h"
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <functional>
#include <numeric>
#include <cmath>
using namespace std;

int t;
const int N = 10001;
int arr[N];

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	for (int i = 0; i < N; i++)
	{
		arr[i] = 0;
	}
	for (int x = 1; x < 101; x++)
	{

		for (int y = 1; y <101; y++)
		{
			for (int z = 1; z <101; z++)
			{
				long long s = x * x + y * y + z * z + x * y + x * z + y * z;
				if (s < N) arr[s - 1] ++;
			}

		}
	}
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		cout << arr[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k;
	string s;
	cin>>k>>s;
	if (s.size()<=k)   cout<<s;
	else
	{
		string temp=s.substr(0,k);
		temp+="...";
		cout<<temp;
	}
	return  0;
} 

Measured memory_bytes: 3628
N = int(input())
task = [tuple(map(int, input().split())) for _ in range(N)]

if sum(map(lambda x: x[0], task)) > max(map(lambda x: x[1], task)):
    print("No")
else:
    task.sort(key=lambda x: x[1])
    time = 0
    judge = True
    for t in task:
        time += t[0]
        if time > t[1]:
            print("No")
            judge = False
            break
    if judge:
        print("Yes")

Measured memory_bytes: 31980
#include<stdio.h>

int main(void)
{
   int n, x, l[100], i, s;

   scanf("%d%d",&n,&x);
   for(i=0;i<n;i++)
      scanf("%d",&l[i]);

   i=0;
   while((s<=x)&&(i<n)){
      s+=l[i];
      i++;
   }

   if((i!=n)||(s>x))
      printf("%d\n",i);
   else
      printf("%d\n",i+1);
   return 0;
}

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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18 + 1;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N, M;
VL S, T;
ll dp[ll(2 * 1e3 + 1)][ll(2 * 1e3 + 1)];
ll sum[ll(2 * 1e3 + 1)][ll(2 * 1e3 + 1)];

signed main() {
    cin >> N >> M;
    REP(i, N) { S.emplace_back(IN()); }
    REP(i, M) { T.emplace_back(IN()); }
    ll ans = 0;
    REP(i, N) {
        REP(j, M) {
            if(S[i] == T[j]) {
                dp[i + 1][j] += sum[i][j - 1] + 1;
                dp[i + 1][j] %= MOD;
            }
            (sum[i + 1][j] += MOD + sum[i][j] - sum[i][j - 1] + dp[i + 1][j]) %= MOD;
            if(j > 0) (sum[i + 1][j] += sum[i + 1][j - 1]) %= MOD;
        }
    }
    cout << sum[N][M - 1] + 1 << "\n";
}


Measured memory_bytes: 62720
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define per(i,l,r) for(int i=(r)-1;i>=(l);--i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl

//-----
const int N = 4e2 + 7, MOD = 1e9 + 7;
void inc(int &a, int b) { if ((a += b) >= MOD) a -= MOD; }
int add(int a, int b) { if ((a += b) >= MOD) a -= MOD; return a; }
int mul(int a, int b) { return ll(a) * b % MOD; }
int n, c, a[N], b[N], g[N][N], dp[N][N];
int sum(int p, int a, int b) { return add(g[p][b], MOD - g[p][a - 1]); }
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> n >> c;
	rep(i, 1, n + 1) cin >> a[i];
	rep(i, 1, n + 1) cin >> b[i];
  rep(j, 1, N) g[0][j] = 1;
  rep(i, 1, N) rep(j, 1, N) g[i][j] = mul(g[i - 1][j], j);
	rep(i, 0, N) rep(j, 1, N) inc(g[i][j], g[i][j - 1]);
	rep(j, 0, c + 1) dp[1][j] = sum(j, a[1], b[1]);
	rep(i, 2, n + 1)
		rep(j, 0, c + 1)
			rep(ci, 0, j + 1)
				inc(dp[i][j], mul(dp[i - 1][j - ci], sum(ci, a[i], b[i])));
	cout << dp[n][c];
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    int n;
    cin >> n;

    vector<int> b(n * 2);

    int j = n, d = 1, s = 1, m = n;
    if (n % 2 == 0) s *= -1;

    for (int i = 0; i < n; i++) {
        m = min(m, j);
        cin >> b[j];

        j += s * d;
        d++;
        s *= -1;
    }

    for (int i = 0; i < n; i++) {
        cout << b[m + i] << " \n"[i == n - 1];
    }

    return 0;
}

Measured memory_bytes: 3712
#include<stdio.h>
int main(void){
int H,W,x,y;
while(1){
scanf("%d %d",&H,&W);
if(H == 0 && W ==0)
break;
for(y=0; y<H;y++){
for(x=0; x<W; x++){
if(x ==0 || y == 0 || x == W-1 ||y == H-1){
printf("#");
}else{
printf(".");
}
}
printf("\n");
}
printf("\n");
}
return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define ff first 
#define ss second  
typedef pair<int,int> pp;
bool com(pp x,pp y){
    return x.ff<y.ff;
} 
int N=1e5+9;
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0); 
	int h,w,m,ans=0;
	cin>>h>>w>>m;
	vector<int> col(w+1,0),rw(h+1,0); 
	map<int,map<int,int>> mp;
	for(int i=0;i<m;i++){
	    int u,v;
	    cin>>u>>v;
	    mp[u][v]++;
	    rw[u]++;
	    col[v]++;
	}
	int r=0,c=0,row,co;
	for(int i=1;i<=h;i++){
	    //cout<<rw[i]<<" ";
	    if(rw[i]>r){
	        r=rw[i];
	        row=i;
	    }
	}
	//cout<<"\n";
	for(int i=1;i<=w;i++){
	    if(col[i]>c){
	        c=col[i];
	        co=i;
	    }
	    else if(col[i]==c&&!mp[row][i]) co=i;
	}
	for(int i=1;i<=h;i++){
	    if(r==rw[i]&&!mp[i][co]) row=i;
	}
	//cout<<row<<" "<<co<<endl;
	if(mp[row][co]) r--;
	cout<<r+c<<"\n";
	return 0; 
	
}


Measured memory_bytes: 75728
#include<stdio.h>
#define lln long long int
using namespace std;


int main()
{
    lln n,sum=0;
    scanf("%lld",&n);
    for(int i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0){
            sum=sum+i;
        }
    }
    printf("%lld",sum);
}


Measured memory_bytes: 1736
import heapq

n, m = map(int, input().split())
aaa = [-1 * int(a) for a in input().split()]
heapq.heapify(aaa)

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

Measured memory_bytes: 14188
h, w = gets.split.map(&:to_i)
l = []
h.times do
  ll = gets.chomp.split('')
  l << ll
end

dp = Array.new(h,0){Array.new(w,0)}
h.times do |hi|
  w.times do |wi|
    if hi == 0
      if wi == 0
        if l[hi][wi] == '#'
          dp[hi][wi] += 1
        end
      else
        if l[hi][wi] == '#'
          if l[hi][wi-1] != '#'
            dp[hi][wi] += 1
          end
        end
        dp[hi][wi] += dp[hi][wi-1]
      end
    else
      if wi == 0
        if l[hi][wi] == '#'
          if l[hi-1][wi] != '#'
            dp[hi][wi] += 1
          end
        end
        dp[hi][wi] += dp[hi-1][wi]
      else
        if dp[hi-1][wi]==dp[hi][wi-1]
          if l[hi-1][wi]=='.' and l[hi][wi-1]=='#'
            if l[hi][wi] == '#'
              if l[hi][wi-1] != '#'
                dp[hi][wi] += 1
              end
            end
            dp[hi][wi] += dp[hi][wi-1]
          elsif l[hi][wi-1]=='.' and l[hi-1][wi]=='#'
            if l[hi][wi] == '#'
              if l[hi-1][wi] != '#'
                dp[hi][wi] += 1
              end
            end
            dp[hi][wi] += dp[hi-1][wi]
          else
            if l[hi][wi] == '#'
              if l[hi-1][wi] != '#'
                dp[hi][wi] += 1
              end
            end
            dp[hi][wi] += dp[hi-1][wi]
          end
        elsif dp[hi-1][wi]<dp[hi][wi-1]
          if l[hi][wi] == '#'
            if l[hi-1][wi] != '#'
              dp[hi][wi] += 1
            end
          end
          dp[hi][wi] += dp[hi-1][wi]
        else
          if l[hi][wi] == '#'
            if l[hi][wi-1] != '#'
              dp[hi][wi] += 1
            end
          end
          dp[hi][wi] += dp[hi][wi-1]
        end
      end
    end
  end
end
puts dp[h-1][w-1]


Measured memory_bytes: 4860
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

double W,H,x,y;
int main(){
    cin>>W>>H>>x>>y;
    bool flag = (x==W/2 && y == H/2);
    cout << W*H/2 << " " << flag <<'\n';
}

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

using namespace std;

typedef long long ll;

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#else
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    string s;
    cin >> s;
    for (auto c : s)
    {
        if (c == ',')
        {
            cout << ' ';
            continue;
        }
        else
        {
            cout << c;
        }
    }
}



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

typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

#define INF (int)(1e9)

#define rep(i,n) for(int i=0; i<(n); ++i)
#define REP(i,start,end) for(int i=(start);i<=(end);++i)
#define all(n) begin(n),end(n)

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n,a,b;
	cin >> n >> a >> b;

	int p1 = a * n;
	int p2 = b;

	if(p1 < p2) cout << p1 << endl;
	else cout << p2 << endl;
	
	return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline

    class Bit:
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (n + 1)

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x):
            while i <= self.size:
                self.tree[i] += x
                i += i & -i


    N = int(input())
    A = [0] * (2*N)
    idx_W = [0] * (N+1)
    idx_B = [0] * (N+1)
    for i in range(N*2):
        c, a = input().split()
        if c == 'B':
            A[i] = int(a)
            idx_B[A[i]] = i+1
        else:
            A[i] = -int(a)
            idx_W[-A[i]] = i + 1

    cost_W = [[0] * (N+2) for _ in range(N+1)]
    cost_B = [[0] * (N+2) for _ in range(N+1)]
    cost_W_imos = [0] * (N+1)
    cost_B_imos = [0] * (N+1)
    for i in range(2*N):
        if A[i] > 0:
            Ai = A[i]
            cost_W_imos[Ai] = 1
            for j in range(N, 0, -1):
                if j == N:
                    cost_B[Ai][j] = cost_B_imos[j]
                else:
                    cost_B[Ai][j] = cost_B[Ai][j+1] + cost_B_imos[j]
        else:
            Ai = -A[i]
            cost_B_imos[Ai] = 1
            for j in range(N, 0, -1):
                if j == N:
                    cost_W[Ai][j] = cost_W_imos[j]
                else:
                    cost_W[Ai][j] = cost_W[Ai][j + 1] + cost_W_imos[j]

    inv_W = [0] * (N+1)
    inv_B = [0] * (N+1)
    bit_W = Bit(2*N+1)
    bit_B = Bit(2*N+1)
    for i in range(N, 0, -1):
        inv_W[i] = bit_W.sum(idx_W[i])
        inv_B[i] = bit_B.sum(idx_B[i])
        bit_W.add(idx_W[i], 1)
        bit_B.add(idx_B[i], 1)

    inf = (N*2)**2
    dp = [[inf] * (N+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N+1):
        for j in range(N+1):
            if i+1 <= N:
                dp[i+1][j] = min(dp[i+1][j], dp[i][j] + cost_W[i+1][j+1] + inv_W[i+1])
            if j+1 <= N:
                dp[i][j+1] = min(dp[i][j+1], dp[i][j] + cost_B[j + 1][i + 1] + inv_B[j + 1])
    print(dp[N][N])


if __name__ == '__main__':
    main()


Measured memory_bytes: 140252
def myAnswer(s:str) -> int:
   start = 0
   end = 0
   for n,string in enumerate(s):
      if(string =="A"):
         start = n
         break
   for n,string in enumerate(s[::-1]):
      if(string == "Z"):
         end = len(s) - n
         break
   return end - start





def modelAnswer():
   tmp=1
def main():
   s = (input())
   print(myAnswer(s))

if __name__ == '__main__':
   main()

Measured memory_bytes: 3516
N = int(input())
F = [int(input().replace(' ', ''), 2) for i in range(N)]
P = [[int(j) for j in input().split()] for j in range(N)]

ans = -float('inf')

for i in range(1, 2**10):
    temp = 0
    for j in range(N):
        temp += P[j][bin(i&F[j]).count('1')]
    ans = max(ans, temp)

print(ans)

Measured memory_bytes: 3064
//
//  main.cpp
//  GCJ
//
//  Created by shitian.ni on 2018/06/19.
//  Copyright © 2018 shitian.ni. All rights reserved.
//

#include <iostream>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <algorithm>
using namespace std;


int n,m;
unordered_map<int,vector<int> > xy;
vector<int>p;
vector<bool>visited;
vector<int>idx;
void dfs(int x){
    
    visited[x] = true;
    
    idx.push_back(x);
    if(xy[x].size()==0){
        return;
    }
    vector<int> cur = xy[x];
    
    for(auto y:cur){
        if(visited[y])continue;
        dfs(y);
    }
}
int main() {
    cin>>n>>m;
    
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        x--;
        p.push_back(x);
        visited.push_back(false);
        xy[i] = vector<int>();
    }
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        if(x>y)swap(x,y);
        x--;
        y--;
        xy[x].push_back(y);
        xy[y].push_back(x);
    }

    int total = 0;
    for(int x=0;x<n;x++){
        if(!visited[x]){
            idx.clear();
            dfs(x);
            unordered_set<int>values;
            for(int i=0;i<idx.size();i++){
                values.insert(p[idx[i]]);
            }
            for(auto id :idx){
                if(values.find(id)!=values.end()){
                    total++;
                }
            }
        }
    }
    cout<<total<<endl;
    return 0;
}


Measured memory_bytes: 18076
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;

/*
作業は平行して行える


*/

int G[1000][1000];//[A]から[B]へ行くコスト
int d[1000];//最短（というのか？）

int main(){
	int n,m;//結合点数/作業数
	cin>>n>>m;
	
	for(int i=0,a,b,c;i<m;i++){
		//AからBへ行くのにCかかる
		cin>>a>>b>>c;
		G[a][b]=c;
	}
	
	queue<int>St;
	St.push(0);
	
	for(int now;!St.empty();St.pop()){
		now=St.front();
		
		for(int i=0;i<n;i++){
			if(G[now][i]){
				//iへ行けるなら
				
				if(d[now]+G[now][i]>d[i]){
					//今いる地点の最短+iへのコストがiの最短より大きいなら更新
					
					d[i]=d[now]+G[now][i];
					St.push(i);
					
					
				}
			}
		}
	}
	
	cout<<d[n-1]<<endl;
	
	return 0;
}


Measured memory_bytes: 2760
import java.io.*;
 
//class Main{
//    public static void main(String[] args) throws Exception{
//        int x, ans;
//     
//        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//        x = Integer.parseInt(br.readLine());
//         
//        ans = x*x*x;
//        System.out.println(ans);
//    }
//}

class Main {
    public static void main(String[] arg)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        String[] div = str.split(" ");
        int s =  Integer.parseInt(div[0]);
        int l =  Integer.parseInt(div[1]);
        System.out.println(s*l + " "+ 2*(s+l));
    }   
}

Measured memory_bytes: 24116