akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
 
#define lli long long int
#define endl "\n"
 
using namespace std;
 
typedef long long int LLI;
typedef double DB;
 
void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}
 
 
bool comparator(pair<lli,lli> a,pair<lli,lli> b)
{
    if(a.first>b.first)
        return true;
    else if (a.first==b.second)
    {
        if(a.second>=b.second)
            return false;
        return true;
    }
    return false;
}
 
int mods(int x)
{
    if(x>0)
        return x;
    return -x;
}
 
lli gcd(lli a,lli b)
{
    return __gcd(a,b);
}
 
lli lcm(lli x,lli y,lli z)
{
    lli j=gcd(x,y);
    lli k=gcd(y*x/j,z);
    return (((x*y)/j)*z)/k;
} 

int arr[3][3];
bool vis[3][3]={0};

int main()
{
    fastio();
    int n; cin>>n; int arr[n];
    for(int i=0;i<n;++i)
    {
        int k; cin>>k;
        arr[k-1]=i+1;
    }
    for(int i=0;i<n;++i) cout<<arr[i]<<" ";
    return 0;
}

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

using namespace std;

int main(){
	
	int a,b,c,x,y;
	
	cin >> a >> b >> c >> x >> y;
	
	int en1,en2,en3;
	
	en1 = a*x+b*y;
	
	en2 = max(x,y)*2*c;
	
	if(x>y)
		en3 = 2*c*y + (x-y)*a;
	else
		en3 = 2*c*x + (y-x)*b;
	
	cout << min({en1,en2,en3}) ;
	
	return 0;
}

Measured memory_bytes: 256
from collections import deque
N, M, K = map(int,input().split())
friendlist = [[] for _ in range(N+1)]
for n in range(M):
    A, B = map(int,input().split())
    friendlist[A].append(B)
    friendlist[B].append(A)

blocklist = [[] for _ in range(N+1)]
for n in range(K):
    C, D = map(int, input().split())
    blocklist[C].append(D)
    blocklist[D].append(C)

whatgroup = [-1 for _ in range(N+1)]
visited = [-1] * (N+1)
d = deque()
leaderdic = {}
for person in range(1,N+1):
    d.append(person)
    leader = person
    cnt = 0
    while len(d)>0:
        nowwho = d.popleft()
        if whatgroup[nowwho] != -1:
            continue
        d.extend(friendlist[nowwho])
        whatgroup[nowwho] = leader
        cnt += 1
    if cnt != 0:
        leaderdic[leader] = cnt
for person in range(1,N+1):
    ans = leaderdic[whatgroup[person]]
    ans -= 1
    ans -= len(friendlist[person])
    for block in blocklist[person]:
        if whatgroup[person]==whatgroup[block]:
            ans -= 1
    print(ans)

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

using namespace std;

int main(void)
{
	int n, m, c;
	cin >> n >> m >> c;

	vector<int> b(m);
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	int a;
	int sum;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		sum = 0;
		for (int j = 0; j < m; j++) {
			cin >> a;
			sum += a * b[j];
		}
		if (sum + c > 0) {
			ans++;
		}
	}
	cout << ans << endl;
	
	return 0;
}

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


int main()
{
    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    ll dis=x/d;
    if (dis>=k)
    cout<<x-(k*d);
    else
    {
        x=x-(dis*d);
        k-=dis;
        if (k%2)
        {
            x-=d;
            x=abs(x);
        }
        cout<<x;
    }
}

Measured memory_bytes: 3640
s=gets.chomp
nagasa=s.size
han=((nagasa-1)/2).to_i
dame=0
j=nagasa-1
for i in 0..han-1
  if s[i]!=s[j]
    dame=1
  end
  j-=1
end
han1=((han-1)/2).to_i
j=han-1
for i in 0..han1-1
  if s[i]!=s[j]
    dame=1
  end
  j-=1
end
han2=((nagasa+3)/2).to_i
j=nagasa-1
for i in han2-1..nagasa-1
  if s[i]!=s[j]
    dame=1
  end
  j-=1
end
if dame==1
  puts "No"
else
  puts "Yes"
end


Measured memory_bytes: 14408
#include<stdio.h>
int main(void){
int x,a,b,all,ALL,i,ans;
for(;;){
    all=0,ALL=0;
    scanf("%d",&x);
    if(x==0)break;
        for(i=0;i<x;i++){
            a=0,b=0;
            scanf("%d %d",&a,&b);
            ans=a+b;
            if(a>b){
                all=all+ans;
            }
            if(b>a){
                ALL=ALL+ans;
            }
            if(a==b){
                all=all+a;
                ALL=ALL+b;
            }
        }
        printf("%d %d\n",all,ALL);
    }
return 0;
}

Measured memory_bytes: 600
import sys
N, M = map(int, input().split())
S = []
for _ in range(M):
    s, c = map(int, input().split())
    S.append([s, str(c)])

if N == 1:
    for x in range(0, 10):
        check = True
        x = str(x)
        for s in S:
            if x[s[0] - 1] == s[1]:
                continue
            else:
                check = False

        if check:
            print(int(x))
            sys.exit()
            

if N == 2:
    for x in range(10, 99):
        check = True
        x = str(x)
        for s in S:
            if x[s[0] - 1] == s[1]:
                continue
            else:
                check = False

        if check:
            print(int(x))
            sys.exit()


if N == 3:
    for x in range(100, 999):
        check = True
        x = str(x)
        for s in S:
            if x[s[0] - 1] == s[1]:
                continue
            else:
                check = False

        if check:
            print(int(x))
            sys.exit()
print(-1)






Measured memory_bytes: 39024
//Divide a Cuboid

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<int,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    vector<ll>a(3);
    rep(i,0,3)cin>>a[i];
    sort(range(a));
    rep(i,0,3){
        if(a[i]%2==0){cout<<0<<nnn;return 0;}
    }
    cout<<a[0]*a[1]<<nnn;
    return 0;
}

Measured memory_bytes: 256
import itertools
import numpy as np

N = int(input())

l = []
d = {}
for i in range(1, N+1):
    x, y = [int(n) for n in input().split(' ')]
    l.append(i)
    d[i] = (x, y)

temp = list(itertools.permutations(l))

length = []
for tmp in temp:
    length_i = 0
    for i in range(1, len(tmp)):
        length_i += np.sqrt((d[tmp[i]][0]-d[tmp[i-1]][0])**2+(d[tmp[i]][1]-d[tmp[i-1]][1])**2)
    length.append(length_i)

print(np.average(length))

Measured memory_bytes: 20256
package main

import (
        "fmt"
)

func babble(in []int) []int {
        tin := in
        for ii := 0; ii < len(tin)-1; ii++ {
                for jj := ii + 1; jj < len(tin); jj++ {
                        if tin[ii] < tin[jj] {
                                tm := tin[ii]
                                tin[ii] = tin[jj]
                                tin[jj] = tm
                        }
                }
        }
        return tin
}

func main() {
        n := 0
        fmt.Scan(&n)

        a := make([]int, n)
        for ii := 0; ii < len(a); ii++ {
                fmt.Scan(&a[ii])
        }
        out := babble(a)

        turn := true
        alice := 0
        bob := 0
        for jj := 0; jj < len(out); jj++ {
                if turn {
                        alice += out[jj]
                        turn = false
                } else {
                        bob += out[jj]
                        turn = true
                }
        }
        fmt.Println(alice - bob)
}

Measured memory_bytes: 512
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int H = 5;
const int W = 5;
const int D = 4;
const string DIR = "RULD";

int v[H][W][D], my[4] = {0, -1, 0, 1}, mx[4] = {1, 0, -1, 0}, d = 0, y = 0, x = 1;

int main() {
  REP(i, 9){
    string s; cin >>s;
    if(i % 2) REP(j, s.length()) if(s[j] == '1') v[(i + 1) / 2 - 1][j][3] = v[(i + 1) / 2][j][1] = true;
    if(!(i % 2)) REP(j, s.length()) if(s[j] == '1') v[i / 2][j][0] = v[i / 2][j + 1][2] = true;
  }
  stringstream ss; ss << 'R';
  while(y != 0 || x != 0){
    if(v[y][x][(d + 1) % 4]){
      d = (d + 1) % 4; y += my[d]; x += mx[d];
      ss << DIR[d];
    } else if (v[y][x][d]){
      y += my[d]; x += mx[d];
      ss << DIR[d];
    } else{
      d = (d + 3) % 4;
    }
  }
  cout <<ss.str() <<endl;
  return 0;
}

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

typedef long long ll ; 
typedef unsigned long long ull ; 
typedef vector<int> vi ; 
typedef vector<vi> vii ;
typedef vector<ll> vl ;
typedef vector<vl> vll ;
typedef set<int> si ; 
typedef map<int,int> mii ; 
typedef map<ll,ll>  mll ; 
typedef map<string,int> msi ;
typedef set<ll> sl ; 
typedef set<char> sc ; 
typedef pair<int,int> pii ;


#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
const int INF = 1 << 29 ; 
#define MOD (ll)(1e9+7)
#define eps 1e-6
#define pb push_back 
#define mp make_pair 
#define DEBUG(x)		cout << '>' << #x << ':' << x << endl;
#define F first 
#define S second 
#define all(s) s.begin,s.end() 

int main() 
{
	ios::sync_with_stdio(0) ;
	cin.tie(NULL) ; 
	//freopen("input.txt","r",stdin);
	int h , w;
	cin >> h >> w;
	string a[h];
	REP(i,h) cin >> a[i];
	long long dp[h][w];
	REP(i,h) REP(j,w) dp[i][j] = 1;
	for(int i = 1 ; i < w; ++i) {
		if(a[0][i] == '#') dp[0][i] = 0;
		else dp[0][i] = dp[0][i-1];
	}
	for(int i = 1 ; i < h; ++i) {
		if(a[i][0] == '#') dp[i][0] = 0;
		else dp[i][0] = dp[i-1][0];
	}
	for(int i = 1; i < h; ++i) {
		for(int j = 1; j < w; ++j) {
			if(a[i][j] == '#') dp[i][j] = 0;
			else dp[i][j] = dp[i-1][j] + dp[i][j-1];
			dp[i][j] %= MOD;
		}
	}
	cout << dp[h-1][w-1] << endl;
	return 0 ; 
}



Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
int main(){
 string s;
 cin >> s;
 int jkjkjk = 0;
 if(s.at(0) == '1'){
	jkjkjk++;
 }
 if(s.at(1) == '1'){
	jkjkjk++;
 }
 if(s.at(2) == '1'){
 	jkjkjk++;
 }
 cout << jkjkjk << endl;
}

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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    ans += y - x + 1;
  }
  cout << ans << endl;
}

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

int beau = 1000000007;

int main() {
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	cout << x2 - y2 + y1 << " " << y2 + x2 - x1 << " ";
	cout << x1 - y2 + y1 << " " << y1 - x1 + x2;
	return 0;
}


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

int main()
{
    int n,i, m,c1=0,c2=0;
    cin >> n;
    set <int> winner;
    set <int>::iterator it1;
    multiset <int> loser;
    multiset <int>::iterator it2;
    for(i=0; i<n; i++)
    {
        cin >> m;
        winner.insert(m);
        loser.insert(m);
    }
    it1=winner.begin();
    it2=loser.begin();

    for(i=0; it1!=winner.end(); i++)
    {
        if(*it1==*it2)
        {
            c1 = c1+1;

            it2++;
        }
        else
        {
            it1++;
            c2 = c2 + (c1&1);

            c1 = 0;
        }
    }
    cout << c2 + (c1&1);

}


Measured memory_bytes: 12920
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

int main(void){
    ll n, a, b;
    cin >> n >> a >> b;

    if((b - a) % 2 != 0){
        ll ans1 = a;
        ll bplace = b - a;
        ans1 = ans1 + (bplace / 2);

        ll ans2 = n - b + 1;
        ll aplace = a + (n - b + 1);
        if(aplace != n){
            ans2 = ans2 + ((n - aplace) / 2);
        }
        cout << min(ans1, ans2) << endl;
    } else {
        cout << (b - a) / 2 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int A, B, C, K;
  	cin >> A >> B >> C >> K;
  	int M = max({A, B, C});
  	for(; K > 0; K--){
      	M *= 2;
    }
    cout << M + A + B + C - max({A, B, C});
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
const int N=1e9+7;
long long dp[2010][2010];
int main()
{
	cin>>n;
	for(int i=3;i<=n;i++) dp[1][i]=1;
	for(int i=2;i<=(n/3+1);i++)
	{
		for(int j=3*i;j<=n;j++)
		for(int k=3;k<=j-(3*(i-1));k++)
		dp[i][j]=dp[i][j]+dp[i-1][j-k]%N;
	}	
	long long ans=0;
	for(int i=1;i<=n;i++)
	ans=ans+dp[i][n]%N;
	printf("%lld\n",ans%N);
	return 0;
}

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


const int INF = 1e9;

#define int				long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define ALL( a )        (a).begin(), (a).end()             

bool compare( pair<int, int>& a, pair<int, int>& b ) {
	return a.first < b.first || ( a.first == b.first && a.second > b.second );
}

signed main() {
	int n; cin >> n;
	vector<pair<int, int> > r( n * 2 );

	int a, b;
	REP( i, n ) {
		cin >> a >> b;
		r[i * 2] = make_pair( a, 1 );
		r[i * 2 + 1] = make_pair( b, -1 );
	}

	sort( ALL( r ), compare );

	int ans = 0, sum = 0;
	REP( i, n * 2 ) {
		sum += r[i].second;
		ans = max( ans, sum );
	}

	cout << ans << endl;
}


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int T, A, B, rtV, s, e;
	long long V, ans;
	for (cin >> T; T; T--) {
		cin >> A >> B;
		if (A == 1 && B == 1) {
			cout << "0\n";
			continue;
		}
		V = 1LL * A*B - 1;
		s = 1, e = 1e9;
		while (s <= e) {
			int m = (s + e) >> 1;
			if (1LL * m*m <= V) s = m + 1;
			else e = m - 1;
		}
		ans = 2 * (rtV = e);
		if (rtV == V / rtV) ans--;
		if (A <= rtV) ans--;
		if (B <= rtV) ans--;
		cout << ans << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    int a[SIZE];
    int l[SIZE], r[SIZE];
    for( int i = 0; i < n; ++i ) {
        cin >> a[i];
        if( i ) l[i] = __gcd( l[i - 1], a[i] );
        else l[i] = a[i];

    }

    for( int i = n - 1; i >= 0; --i ) {
        if( i != n - 1 ) {
            r[i] = __gcd( r[i + 1], a[i] );

        } else {
            r[i] = a[i];

        }
    }
    
    int res = r[1];
    for( int i = 1; i < n - 1; ++i ) {
        res = max( __gcd( l[i - 1], r[i + 1] ), res );

    }

    cout << max( res, l[n - 2] ) << endl;

    return 0;
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dd double
#define pb push_back
#define mp make_pair
#define f first
#define s second
int main()
{
    int n,key,val,i,cnt=0;
    cin>>n;
    vector<pair<int,int>>vec;
    for(i=0;i<n;i++)
	{
		cin>>key>>val;
		vec.pb(mp(key,val));
	}
	for(i=0;i<n;i++)
	{
		if(vec[i].f==vec[i].s)
		{
			cnt++;
			if(cnt>=3)
			{
				cout<<"Yes"<<endl;
				return 0;
			}
		}
		else
		{
			cnt=0;
		}
	}
	if(cnt>=3)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define IN(x, a, b) x >= a and x < b

using namespace std;
using ll = long long;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> constexpr T INF = numeric_limits<T>::max() / 2;

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

  int N, M;
  cin >> N >> M;
  vector<vector<int>> dp(M + 1, vector<int>(pow(2, N), INF<int>));
  dp.at(0).at(0) = 0;
  REP(i, M) {
    int cost, nkinds;
    cin >> cost >> nkinds;
    int key = 0;
    REP(j, nkinds) {
      int kind;
      cin >> kind;
      key |= (1 << (kind - 1));
    }
    REP(bit, pow(2, N)) {
      chmin(dp.at(i + 1).at(bit | key), dp.at(i).at(bit) + cost);
      chmin(dp.at(i + 1).at(bit), dp.at(i).at(bit));
    }
  }

  int ans = dp.at(M).at(pow(2, N) - 1);
  cout << (ans == INF<int> ? -1 : ans) << endl;

  return 0;
}

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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Paste snippets here!!

//

void solve(std::string S) {
  int N = S.size();
  ll ret=0;
  rep(i,(int)(N/2)){
    if(S[i]!=S[N-1-i]) ret++;
  }
  cout << ret << endl;
}

int main() {
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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;
}


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N; cin >> N;
  // ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  vector<ll> a(N); rep(i, N) cin >> a[i];
  
  ll ans = 1000;
  ll kabu = 0;
  ll day = 0;
  while(day < N - 1) {

    if(a[day] < a[day + 1]) {

      kabu = ans / a[day];
      ans = ans % a[day];
      day ++;
      while(day < N - 1 && a[day] <= a[day + 1]) {
	day ++;

      }
    } else
    if(a[day] > a[day + 1]) {

      ans += kabu * a[day];
      kabu = 0;
      day ++;
      while(day < N - 1 && a[day] >= a[day + 1]) {
	day ++;

      }
    } else {
      day++;
    }
  }
  ans += kabu*a[N-1];

  
  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3620
c=[list(map(int,input().split())) for i in range(3)]


  
for i in range(101):
  info=True
  a1=i
  b1=c[0][0]-a1
  b2=c[0][1]-a1
  b3=c[0][2]-a1
  a2=c[1][0]-b1
  a3=c[2][0]-b1
  if min(a1,a2,a3,b1,b2,b3)<0:
    info=False
  if c[1][1]!=a2+b2:
    info=False
  if c[2][1]!=a3+b2:
    info=False
  if c[1][2]!=a2+b3:
    info=False
  if c[2][2]!=a3+b3:
    info=False
  
  if info:
    print("Yes")
    break
else:
  print("No")

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    vector<int> hoge(3);
    rep(i, 3)
    {
        cin >> hoge[i];
    }
    SORT(hoge);
    if (hoge[2] == hoge[1] + hoge[0])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <math.h>
#include <assert.h>

#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& v) {
    return is >> v.first >> v.second;
}

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
    for (T& i: v) is >> i;
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& v) {
    return os << v.first << " " << v.second;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
    int n = (int) v.size();
    for (int i = 0; i < n; ++i) os << v[i] << (i == n - 1 ? "" : " ");
    return os;
}

template <typename T>
void in(T& x) {
    std::cin >> x;
}

template <typename T>
void out(const T H) {
    std::cout << (H);
}

template <typename T1, typename... T2>
void out(const T1 H, const T2... T) {
    std::cout << (H) << " "; out(T...);
}

template <typename T>
void eout(const char *s, const T H) {
    std::cerr << s << "=" << H << "\n";
}

template <typename T1, typename... T2>
void eout(const char *s, const T1 H, const T2... T) {
    while (*s != ',') std::cerr << *s++;
    std::cerr << "=" << H << " | "; eout(++s, T...);
}

#define nl                std::cout << "\n"
#define err(args...)      eout(#args, args)

#define rep(i, n)         for (int i =  0 ; i < (n); ++i)
#define per(i, n)         for (int i = (n) - 1; i > -1; --i)
#define repr(i, l, r)     for (int i = (l); i < (r); ++i)

#define sz(v)             ((int) v.size())
#define all(v)            (v).begin(), (v).end()
#define lla(v)            (v).rbegin(), (v).rend()

#define no                std::cout << "NO\n"
#define yes               std::cout << "YES\n"

const int INF           = 2147483647;
const long long int LNF = 9223372036854775807LL;

using ll  = long long int;
using vi  = std::vector<int>;
using vb  = std::vector<bool>;
using ii  = std::pair<int, int>;
using iii = std::pair< ii, int>;
using vii = std::vector<ii>;

const int N  = 505050;
const int MD = 1000*1000*1000 + 7;

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

    //int t; in(t); repr(tc, 1, t + 1)
    solve();

    return 0;
}

int solve() {
    int n; in(n);
    vi a(n); in(a);

    int i = 0, ans = 0;
    while (i < n) {
        int j = i + 1;
        while (j < n and a[j] <= a[j - 1]) ++j;
        ans = std::max(j - i - 1, ans);
        i = j;
    }

    out(ans);
    return 0;
}


Measured memory_bytes: 640
n,m=gets.split(' ').map(&:to_i)
a=gets.split(' ').map(&:to_i)
#tajigen = Array.new(4) { Array.new(2,0) }
sum =0
for i in 0..n-1
  sum+= a[i]
end
#puts sum
k=4*m
stand = sum/k + 1
if sum%4 == 0
  stand = sum/k
end

#puts stand

count = 0
for i in 0..n-1
  if a[i] >= stand
    count +=1
  end
end

if count>=m
  puts "Yes"
else
  puts "No"
end


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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9

int main(){
  int N, K;
  cin >> N >> K;
  if(K > (N-1)*(N-2)/2){
    cout << -1 << endl;
    return 0;
  }
  vector<vector<int>> g(N);
  FOR(i, 1, N){
    g[i].push_back(0);
  }
  int cnt = (N-1)*(N-2)/2 - K;
  FOR(i, 1, N){
    if(cnt == 0) break;
    FOR(j, i+1, N){
      if(cnt == 0) break;
      g[i].push_back(j);
      cnt--;
    }
  }
  cout << N-1 + (N-1)*(N-2)/2-K << endl;
  REP(i, N){
    REP(j, g[i].size()){
      cout << i+1 << " " << g[i][j]+1 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int A = sc.nextInt();
      int B = sc.nextInt();
      int C = sc.nextInt();
      int[] E = new int[]{A,B,C};
      Arrays.sort(E);
      
      System.out.println(E[2]*10+E[1]+E[0]);
    }
}

Measured memory_bytes: 35636
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
using namespace std;

int main()
{
    int m;
    cin >> m;
    if(m == 0)
        return 1;
    string cars,sum;
    typedef set<string> set_t;
    set_t A;
    while(m)
    {
        A.clear();
        m--;
        cin >> cars;
        for(size_t i=0;i<=cars.size();i++)
        {
            string l, r;
            string ln = l = cars.substr(0,i);
            string rn = r = cars.substr(i);
            reverse(ln.begin(),ln.end());
            reverse(rn.begin(),rn.end());
            sum = l + r;
                A.insert(sum);
            sum = l + rn;
            A.insert(sum);
            sum = ln + r;
            A.insert(sum);
            sum = ln + rn;
            A.insert(sum);
            sum = r + l;
            A.insert(sum);
            sum = rn + l;
            A.insert(sum);
            sum = r + ln;
            A.insert(sum);
            sum = rn + ln;
            A.insert(sum);
        }
        cout << A.size() << endl;
    }
}


Measured memory_bytes: 3216
n=int(input())
a=list(map(int,input().split()))
MOD=10**9+7
tot=(sum(a))%MOD
ans=0
for i in range(n):
  ans=(ans+a[i]*(tot-a[i]))%MOD
ans=(ans*pow(2,MOD-2,MOD))%MOD
print(ans)

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

int main() {
    long long n, m;
    cin >> n >> m;


    if(n == 1 && m == 1) cout << 1 << endl;
    else if (n == 1 || m == 1) cout << n * m - 2 << endl;
    else cout << (n - 2) * (m - 2) << endl; 

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string str;
int cnt=0;
bool fu[100001];

int main(void){
	cin >> str;
	bool flag=true;
	if(str[0]==str[str.size()-1])flag=false;
	if(str.size()%2==0)flag^=true;
	printf("%s\n",flag?"First":"Second");
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve(){
  int n,m,x;
	cin>>n>>m>>x;
	vi v(m);
	rep(i,m) cin>>v[i];
	set<int> s;
	rep(i,m) s.insert(v[i]);
	int a=0;
	for(int i=x-1;i>=0;i--){
		if(s.count(i)) a++;
	}
	int b=0;
	for(int i=x+1;i<=n;i++){
		if(s.count(i)) b++;
	}
	out(min(a,b));
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	s := getNextString(scanner)
	n := len(s)

	ans := "First"

	if s[0] == s[n-1] && n%2 != 0 {
		ans = "Second"
	}
	if s[0] != s[n-1] && n%2 == 0 {
		ans = "Second"
	}

	fmt.Fprintln(writer, ans)

	writer.Flush()
}


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

    string s;
    cin >> s;

    int idx = s.length()-1;
    int ans = 0;
    for(int i=0; i<s.length(); i++){
        if(s[i] != s[idx--]){
            ans++;
        }
        if(idx<=i){
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
  int n;cin >> n;
  ll total=0,x=0,amin=2000000001;
  vector<ll> a(n);
  for(int i=0;i<n;i++){cin >> a[i];total+=a[i];}
  for(int i=0;i<n-1;i++){
    x+=a[i];
    total-=a[i];
    amin=min(amin,abs(x-total));
  }
  cout << amin << endl;
}

Measured memory_bytes: 1792
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

h,w,n = getList()
sy, sx = getList()
taka = input()
aoki = input()

def game(taka, aoki, mt, ma, buf, bmax):
    for ta, ao in zip(taka, aoki):
        if ta == mt:
            buf -= 1
            if buf == 0:
                return False
        if ao == ma:
            buf = min(buf + 1, bmax)

    return True

ga = game(taka,aoki,"U", "D", sy, h)
gb = game(taka,aoki,"D", "U", h - sy + 1, h)
gc = game(taka,aoki,"L", "R", sx, w)
gd = game(taka,aoki,"R", "L", w - sx + 1, w)

if ga and gb and gc and gd:
    print("YES")

else:
    print("NO")

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


int main() {
    int n;
    cin>>n;
    int ca[2][n];
    int c[2][n];
    for(int i=0;i<2;i++){
        for (int j = 0; j < n; ++j) {
            cin>>ca[i][j];
            if(j==0)c[i][0]=ca[i][0];
            else c[i][j]=ca[i][j]+c[i][j-1];
        }
    }
    int maxp=c[0][0]+c[1][n-1];
    for (int k = 1; k < n; ++k) {
        maxp=max(c[0][k]+c[1][n-1]-c[1][k-1],maxp);
    }
    cout<<maxp<<endl;
    return 0;
}

Measured memory_bytes: 256
from math import *
r=pi/180
while 1:
    a,b,c,d=e=map(lambda x: float(x)*r,raw_input().split())
    if e==[-r]*4:break
    print int(round(6378.1*acos((sin(a)*sin(c)+cos(a)*cos(c)*cos(d-b)))))

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

using namespace std;

#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 = long long;
using P = std::tuple<int,int>;

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

constexpr ll MOD = 1000000000 + 7;
int H, W;
std::string S[1100];
ll dp[1100][1100];

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

    std::cin >> H >> W;

    for(int i=0;i<H;++i){
        std::cin >> S[i];
    }

    dp[0][0] = 1;

    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            if(i == 0 && j == 0){
                continue;
            }

            if(S[i][j] == '#'){
                continue;
            }

            if(i - 1 >= 0){
                dp[i][j] = (dp[i][j] + dp[i-1][j]) % MOD;
            }

            if(j - 1 >= 0){
                dp[i][j] = (dp[i][j] + dp[i][j-1]) % MOD;
            }
        }
    }

    ll res = dp[H-1][W-1];
    std::cout << res << std::endl;
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL p = 1e9 + 7;
LL n, a, b, ans;

LL qwe(LL a, LL n) { //快速幂
	LL res = 1LL;
	while(n) {
		if(n & 1) res = res * a % p;
		a = a * a % p;
		n >>= 1LL;
	}
	return res % p;
}

LL inv(LL x) { //逆元
	return qwe(x, p - 2) % p;
}

LL C(LL n, LL m) { //组合数
	LL res = 1LL;
	for(LL i = 1, j = n; i <= m; i++, j--) {
		res = res * j % p;
		res = res * inv(i) % p;
	}
	return res % p;
}

LL lucas(LL a, LL b) {
	if(a < p && b < p) return C(a, b) % p;
	return C(a % p, b % p) * lucas(a / p, b / p) % p;
}

int main() {
	cin >> n >> a >> b;
	ans = (qwe(2LL, n) - (lucas(n, a) % p + lucas(n, b) % p) % p - 1 + p) % p;
	cout << ans << endl;
    return 0;
}

/*
n和m较大, 且p为素数时
Lucas定理作用: c(n, m) mod p
C(n, m) % p = C(n / p, m / p) * C(n % p, m % p) % p
=> Lucas(n, m) % p = Lucas(n / p, m / p) * C(n % p, m % p) % p
*/

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

std::vector <int> v[4];
int s[4][101];

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

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

    for(int i=1; i<=n; i++){
        int x, y;
        scanf("%d%d", &x, &y);

        if(i==1) sef=x;

        v[x-sef].push_back(y);
    }

    for(int i=0; i<4; i++){
        std::sort(v[i].begin(), v[i].end(), cmp);
        for(int j=0; j<(int)v[i].size(); j++)
            s[i][j+1]=s[i][j]+v[i][j];
    }

    int ans=0;
    for(int i=0; i<=(int)v[0].size(); i++)
        for(int j=0; j<=(int)v[1].size(); j++)
            for(int p=0; p<=(int)v[2].size(); p++)
                if(w>=1LL*i*sef+1LL*j*(sef+1)+1LL*p*(sef+2))
                    ans=std::max(ans, s[0][i]+s[1][j]+s[2][p]+s[3][std::min((int)v[3].size(), (w-i*sef-j*(sef+1)-p*(sef+2))/(sef+3))]);

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

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define swap(type ,a ,b) {type t; t=a; a=b; b=t;}
#define forN(i,n) for(i=0;i<n;i++)
#define forR(i,s,n) for(i=s;i<n;i++)
#define ll long long
#define pb(t,d,n) {t p;int i;forN(i,n){cin>>p;d.push_back(p);}}

using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;

typedef vector<pair<int,int>> vpii;

int main(){
    ll int n,a,b,c,d,e,tmp,res,i;
    cin >> n >> a >> b >> c >> d >> e;
    tmp  = a;
    if(a<b) b = a;
    if(b<c) c = b;
    if(c<d) d = c;
    if(d<e) e = d;
    cout << (n+e-1)/e + 4 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n, a, b; cin >> n >> a >> b;
    int x = min(a,b);
    int y = max(0,a+b-n);
    cout << x << " " << y << endl;
}

Measured memory_bytes: 3632
n = int(input())
a = list(map(int,input().split()))
a.sort()
t = 1
 
for i in range(len(a)):
  t *= a[i]
  if t > 10**18:
    break
 
if t > 10**18 :
  print("-1")
else:
  print(str(t))

Measured memory_bytes: 21600
import heapq

n,m = map(int, input().split())
ab = sorted([list(map(int, input().split())) for i in range(n)])
ans = 0
now = 0
heap = []
for rem in range(1,m+1):
  B = 0
  while now < n:
    a,b = ab[now]
    if a > rem:
      break
    heapq.heappush(heap, (-b))
    now += 1
  if len(heap) > 0:
    B = heapq.heappop(heap)
  ans -= B
print(ans)
  

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

using namespace std;

#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int Check(int x,int y,int z)
{
    return x*x+y*y+z*z+x*y+x*z+y*z;
}

int main()
{
    FAST();
    int i,j,k,n,x,cnt[10002]={0};
    cin >> n;
    for(i=1;i<101;i++)
    {
        for(j=1;j<101;j++)
        {
            for(k=1;k<101;k++)
            {
                x=Check(i,j,k);
                if(x <= n)++cnt[x];
            }
        }
    }
    for(i=1;i<=n;i++)cout << cnt[i] << '\n';
    return 0;
}


Measured memory_bytes: 3628
H,W=map(int,input().split())

BW=[]
for i in range(H):
  nextline=list(input())
  for j in range(W):
    if nextline[j]=='#':
      BW.append(nextline)
      break;

columnWlist=[1]*(W)
for i in range(len(BW)):
  for j in range(W):
    if columnWlist[j]==1 and BW[i][j]=='#':
      columnWlist[j]=0

for i in range(len(BW)):
  for j in range(W-1,-1,-1):
    if columnWlist[j]==1:
      BW[i].pop(j)
      
for i in range(len(BW)):
  for j in range(len(BW[0])):
    print(BW[i][j],end='')
  print()

Measured memory_bytes: 4596
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define rv(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int M = 120000;
typedef long long ll;
int n,m,k;
char grid[8][10][10]={{"aa.","..a","..a"},
{"aabc","ddbc","bcaa","bcdd"},
{"aabba","bcc.a","b..cb","a..cb","abbaa"},
{
    "aabc..",
    "ddbc..",
    "..aabc",
    "..ddbc",
    "bc..aa",
    "bc..dd"
},
{
    "aabbcc.",
    "dd.dd.a",
    "..d..da",
    "..d..db",
    "dd.dd.b",
    "..d..dc",
    "..d..dc"
}};
char ans[1001][1001];
void out(int x){
    fo(i,0,x-1) {
        ans[i][x]='\0';
        printf("%s\n",ans[i]);
    }
}
void ass(int x,int y,int num){
    fo(i,0,num+2)
        fo(j,0,num+2)
            ans[i+x][j+y]=grid[num][i][j];
}
int main(){
    while(cin>>n){
        if(2==n) puts("-1");
        else {
            fo(i,0,n-1)
                fo(j,0,n-1)
                    ans[i][j]='.';
            int i;
            for(i=0;n-i*4>7;++i) {
                ass(i*4,i*4,1);
            }
            ass(i*4,i*4,n-i*4-3);
            out(n);
        }
    }
    return 0;
}

Measured memory_bytes: 2176
#include"iomanip"
#include"iostream"
#include"limits"
#include"cmath"
#include"vector"
#include"algorithm"
#include"list"
#include"queue"
#include"stack"
#include"set"
#include"unordered_set"
#include"map"
#include"unordered_map"
#include"string"
#include"cstring"
#include"assert.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pb push_back
#define mset(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn=1e5+10;
ll pre[maxn];
int pri(ll x)
{
    if(x<2)return 0;
    if(x<4)return 1;
    for(ll i=2;i<sqrt(x)+10&&i<x;++i)
    {
        if(x%i==0)return 0;
    }
    return 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for(int i=3;i<maxn-1;i+=2)
    {
        if(pri(i)&&pri( (i+1)/2) )
        {
            pre[i]=1;
        }
        pre[i]+=pre[i-1];
        pre[i+1]+=pre[i];
    }
    int q;
    cin>>q;
    while(q--)
    {
        int l,r;
        cin>>l>>r;
        cout<<pre[r]-pre[l-1]<<'\n';
    }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int absolute(int x, int y){
    int result;
    result = x - y;
    if(result < 0){
        result = - result;
    }
    return result;
}

int main(){
    //input
    int n;
    int a[100];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    //serch
    int result = 0;
    for(int i = 0; i < n - 1; i++){
        for(int j = i + 1; j < n; j++){
            int p = absolute(a[i], a[j]);
            if(p > result){
                result = p;
            }
        }
    }
    //output
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		char S[] = sc.next().toCharArray();
		int hag = 0;
		int sum = 0;
		for(int i = 0; i < S.length / 2; i++){
			sum += isSame(S[i], S[S.length - 1 - i]) ? 0 : 1;
		}
		System.out.println(sum);

	}

	public static boolean isSame(char a, char b){
		return a == b ? true : false;
	}
}


Measured memory_bytes: 23764
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    int n;
    int a;
    int b;
    cin >> n;
    if(n==1){
        cout << "Hello World" << endl;
    }else{
        cin >> a;
        cin >> b;
        cout << a+b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

int h, w, s, s2;
int dp[35][35][35][35];
int dp2[35][35][35][35];
int m[35][35];
int ssum[35][35];

pii go(int l, int r, int u, int b) {
	if(dp[l][r][u][b] != -1) return mp(dp[l][r][u][b], dp2[l][r][u][b]);
	int opt_gn, opt_md;
	if(r - l == 1 && b - u == 1) {
		opt_gn = 1;
		opt_md = m[u][l] - s2;
	}
	else {
		opt_gn = 1, opt_md = ssum[b][r] - ssum[b][l] - ssum[u][r] + ssum[u][l] - s2;
		REP(i, l + 1, r - 1) {
			pii p1 = go(l, i, u, b);
			pii p2 = go(i, r, u, b);
			if(p1.snd < 0 || p2.snd < 0) continue;
			if(opt_gn < p1.fst + p2.fst) {
				opt_gn = p1.fst + p2.fst;
				opt_md = min(p1.snd, p2.snd);
			}
			else if(opt_gn == p1.fst + p2.fst) {
				opt_md = max(opt_md, min(p1.snd, p2.snd));
			}
		}
		REP(i, u + 1, b - 1) {
			pii p1 = go(l, r, u, i);
			pii p2 = go(l, r, i, b);
			if(p1.snd < 0 || p2.snd < 0) continue;
			if(opt_gn < p1.fst + p2.fst) {
				opt_gn = p1.fst + p2.fst;
				opt_md = min(p1.snd, p2.snd);
			}
			else if(opt_gn == p1.fst + p2.fst) {
				opt_md = max(opt_md, min(p1.snd, p2.snd));
			}
		}
	}
	return mp(dp[l][r][u][b] = opt_gn, dp2[l][r][u][b] = opt_md);
}

int main(){
	for (; cin >> h >> w >> s, (h | w | s) != 0; ) {
		s2 = 0;
		rep(i, h) rep(j, w) {
			cin >> m[i][j];
			s2 += m[i][j];
		}
		s2 -= s;
		memset(ssum, 0, sizeof(ssum));
		rep(i, h) rep(j, w) ssum[i + 1][j + 1] = m[i][j];
		rep(i, h) rep(j, w) ssum[i + 1][j + 1] += ssum[i + 1][j];
		rep(i, w) rep(j, h) ssum[j + 1][i + 1] += ssum[j][i + 1];
		memset(dp, -1, sizeof(dp));
		memset(dp2, -1, sizeof(dp2));
		go(0, w, 0, h);
		cout << dp[0][w][0][h] << ' ' << dp2[0][w][0][h] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		long a = sc.nextInt();
		long b = sc.nextInt();
		long c = sc.nextInt();
		if (a == b && b == c && a % 2 == 0) {
			sb.append(-1);
		} else {
			long aa, bb, cc, cnt = 0;
			while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
				aa = (b + c) / 2;
				bb = (a + c) / 2;
				cc = (a + b) / 2;
				a = aa;
				b = bb;
				c = cc;
				cnt++;
			}
			sb.append(cnt);
		}
		System.out.println(sb);
	}
}


Measured memory_bytes: 21844