akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int H,W;
char Map[51][51];
int Num[51][51];
int d[4][2] = {{-1,0},{1,0},{0,-1},{0,1}};

int Count(int x,int y){
    queue<vector<int>> que;
    vector<int> place(2,0);
    que.push({x,y});
    Num[x][y] = 1;
    while(que.size() != 0){
        place = que.front();
        que.pop();
        if(place[0] == H && place[1] == W) return Num[H][W];
        for(int i=0;i<4;i++){
            int nx = place[0] + d[i][0];
            int ny = place[1] + d[i][1];
            if(nx>0 && nx<=H && ny>0 && ny<=W && Num[nx][ny]==-1 && Map[nx][ny]=='.'){
                que.push({nx,ny});
                Num[nx][ny] = Num[place[0]][place[1]] + 1;
            }
        }
    }
    return -1;
}

int main(){
    int white = 0;
    cin >> H >> W;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            cin >> Map[i][j];
            if(Map[i][j] == '.') white++;
            Num[i][j] = -1;
        }
    }
    int count = Count(1,1);
    if(count == -1) cout << -1 << endl;
    else cout << white - count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int bpay(int b,int c,int d,int p){
  if(p<c){
    return b;
  }else{
    return b+d*(p-c);
  }
}
int main(){
  int a,b,c,d,p;
  cin >>a>>b>>c>>d>>p;
  cout << min(a*p,bpay(b,c,d,p))<<endl;
  return 0;
}

Measured memory_bytes: 3072
n = int(input())

x = []

for i in range(n):
	a,b,c = map(int,input().split())
	x.append([c,a,b])
x.sort()
x.reverse()
a = 0
b = 0
for i in range(101):
	for j in range(101):
		for k in range(n):
			if x[k][0] != 0:
				if k == 0:
					a = x[k][0] + abs(i-x[k][1]) + abs(j-x[k][2])
					b += 1
				else:
					if a == x[k][0] + abs(i-x[k][1]) + abs(j-x[k][2]):
						b += 1
			else:
				if a- abs(i-x[k][1]) - abs(j-x[k][2]) <= 0:
					b += 1
		if b == n:
			print(i,j,a)
		b = 0


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;

int main() {
 int n;
  in(n);
  if(n/100==1) n += 800;
  else if(n/100==9) n -= 800;
  if((n%100)/10==1)n+= 80;
  else if((n%100)/10==9)n -= 80;
  if(n%10==1)n += 8;
  else if(n%10 == 9) n -= 8;
  out(n);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define p pair<int,int>
template<class T> void chmax(T& a, T b){if(a < b) a = b;}
template<class T> void chmin(T& a, T b){if(a > b) a = b;}
string S;
int x, y;
bool s[20010], t[20010];

int main(){
    s[10000] = true;
    t[10000] = true;
    
    cin >> S >> x >> y;
    S += 'T';

    vector<int> lr, ud;
    bool f = true;
    bool flag = true;
    int cnt = 0;
    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'T'){
            if(f) x -= cnt, f = false;
            else if(flag) lr.push_back(cnt);
            else ud.push_back(cnt);
            flag = !flag;
            cnt = 0;
        }else{
            cnt++;
        }
    }
    for(int i = 0; i < lr.size(); i++){
        vector<int> ok;
        for(int j = 0; j <= 20000; j++){
            if(s[j]){
                ok.push_back(j - lr[i]);
                ok.push_back(j + lr[i]);
            }
            s[j] = false;
        }
        for(auto& u : ok){
            s[u] = true;
        }
    }
    for(int i = 0; i < ud.size(); i++){
        vector<int> ok;
        for(int j = 0; j <= 20000; j++){
            if(t[j]){
                ok.push_back(j - ud[i]);
                ok.push_back(j + ud[i]);
            }
            t[j] = false;
        }
        for(auto& u : ok){
            t[u] = true;
        }
    }
    cout << (s[10000 + x] && t[10000 + y] ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <algorithm>

// Definitions
#define MAXN
#define elif else if
typedef long long int64;
typedef long double num128;
typedef unsigned long long uint64;

// Variables
int64 k;

// Improve the speed of read-in.
inline bool IsNum(char x) { return ('0' <= x) && (x <= '9'); }
inline int64 ReadNum() {
  int64 sign = 1, val = 0; char tmp = getchar();
  while (!IsNum(tmp)) { if (tmp == '-') {sign = -sign;} tmp = getchar(); }
  while (IsNum(tmp)) { val = val * 10 + tmp - 48; tmp = getchar(); }
  return val * sign;
}

// Functions
inline void Process() {
  int64 val = 7, cnt = 1, flag = 0;
  if (k % 2 == 0) {
    puts("-1");
    return;
  }
  for (val = 7; val % k; val = (val * 10 + 7) % k, cnt++) {
    if (val > k && !flag) {
      flag = 7 % k;
    } elif (flag == val % k) {
      puts("-1");
      return;
    }
    if (cnt > k) {
      puts("-1");
      return;
    }
  }
  printf("%lld\n", cnt);
  return;
}
inline void ReadIn() {
  k = ReadNum();
}

int main() {
  ReadIn();
  Process();
  return 0;
}
/*

1  > 1  | 7
2  > -1
3  > 3  | 777
4  > -1
5  > -1
6  > -1
7  > 1  | 7
8  > -1
9  > 9  | 777777777
10 > -1
11 > 2  | 77
12 > -1
13 > 

*/


Measured memory_bytes: 3760
//My_Template
 
#include<bits/stdc++.h>
 
#define ll long long int
#define vec vector<long long int>
#define pb(a) push_back(a)
#define myfor(n) for(long long int i = 0; i < n; i++)
#define tc(t) long long int t; cin>>t; while(t--)
#define sortt(a) sort(a.begin(), a.end())
#define summ(a) accumulate(a.begin(), a.end(), 0ll)
#define M 1000000007ll
 
using namespace std;


int main() {
 
	//code_goes_here-->

	float d,t,s;
	cin>>d>>t>>s;

	if(d/s <= t)
		cout<<"Yes";
	else
		cout<<"No";
	
	return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
typedef long long int  ll;
long long power(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
long long bigpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int gcd(int a,int b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}
int main() 
{
	int n;
	cin>>n;
	string s[n];
	set<string> st;
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
		st.insert(s[i]);
	}
	cout<<st.size();
	return 0;
}


Measured memory_bytes: 25476
from  collections import Counter

n =int(input())

a = list(input().rstrip().split())

count_num = Counter(a)

result = True

if len(a) == n:
    if n % 2 == 0:
        for i in range(n-1, -1, -2):
            if count_num[str(i)] ==2:
                continue
            else:
                result = False
                break

    else:
        if count_num['0'] == 1:
            for i in range(n-1, 1, -2):                
                if count_num[str(i)] ==2:continue
                else:
                    result = False
                    break
        else:result=False

if result: print(2**int(n/2) % (10**9+7))
else:print(0)
  

Measured memory_bytes: 15972
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int a[6]={1,5,10,50,100,500},b,sum,i;
	sum=0;
	for(i=0;i<6;i++){
		scanf("%d",&b);
		sum+=b*a[i];
	}
	if(sum>=1000){
		printf("1\n");
	}
	else{
		printf("0\n");
	}
	return 0;
}
	


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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    total = sum(A)
    tmp = 0
    ans = float('inf')

    for a in A:
        tmp += a
        #print(abs((total-tmp)-tmp))
        ans = min(abs((total-tmp)-tmp), ans)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 81104
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		int i,j;
		Scanner in = new Scanner(System.in);
		
		i = in.nextInt();
		j = in.nextInt();
		
		if(i<j){
			System.out.println("a < b");
		}else if(i>j){
			System.out.println("a > b");
		}else{
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 17160
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100001
ll pen[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n,m;
    cin>>n>>m;
    ll a[n],ac=0,x;
    string y;
    ifr(i,0,n) a[i]=pen[i]=0;
    for(int i=0;i<m;i++) {
    	cin>>x>>y;x--;
    	if(y[0]=='W'){
    		if(!a[x]) 
    			pen[x]++;
    	}
    	else {
    		if(!a[x]) {ac++;a[x]=1;}
    	}
    }
    ll pe=0;
    ifr(i,0,n) if(a[i]) pe+=pen[i];
    cout<<ac<<" "<<pe;
    return 0;
}

Measured memory_bytes: 1792
# frozen_string_literal: true

n = readline.strip.to_i

a = readline.strip.split.map(&:to_i)

a.sort!
a.reverse!

ans = a[0]

n -= 1

cur = 1
a.slice(1, a.length - 1).each do |v|
  ans += v if cur < n
  cur += 1
  ans += v if cur < n
  cur += 1
  break if cur >= n
end

puts ans


Measured memory_bytes: 31728
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int n;
    cin >> n;
    long a[n];
    rep(i,n){
        cin >> a[i];
    }
    multiset<long> st;
    int ans = 1;
    st.insert(a[0]);
    st.insert(1e9+7);
    for(int i = 1;i<n;i++){
        if(a[i]>*st.begin()){
            auto itr = st.lower_bound(a[i]);
            itr--;
            st.erase(itr);
            st.insert(a[i]);
        }
        else{
            st.insert(a[i]);
        }
    }
    cout << st.size()-1 << endl;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define MOD 998244353
 
using namespace std;


void solve(){
	int k; cin>>k;
	ll s=0;
	for(int i=1; i<=k; i++){
		for(int j=1; j<=k; j++){
			for(int l=1; l<=k; l++){
				s += __gcd(__gcd(i,j),l);
			}
		}
	}
	cout<<s;


}


int main()
{ 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//cout<<fixed<<setprecision(12);
	//memset(dp,-1,sizeof(dp));
	
	int t =1; 
	//cin>>t;

	//int x = t;


	while(t--){
		solve();
		//cout<<"\n";
	}




	return 0;

	}




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

int main() {
  int N, M;
  cin >> N >> M;
  int C;  
  vector<int> counts(N);
  
  for (int i = 0; i < M * 2; i++) {
    cin >> C;
    counts.at(C-1)++;
  }
  
  for (int i = 0; i < N; i++) {
    cout << counts.at(i) << endl;
  }
}


Measured memory_bytes: 3580
s = list(input())
up = int(''.join(s[:2]))
low = int(''.join(s[2:]))

if up > 0 and up < 13:
  if low > 0 and low < 13:
    print('AMBIGUOUS')
  
  elif low >= 0:
    print('MMYY')
  
  else:
    print('NA')

elif low > 0 and low < 13:
  if up >= 0:
    print('YYMM')
  else:
    print('NA')
    
else:
  print('NA')

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

using namespace std;

int main(){
    cin.tie(0);
    cin.sync_with_stdio(0);

    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> v(N, 0);
    for(int i=0; i<Q; i++){
        int a;
        cin >> a;

        v[a-1]++;
    }
    for(auto i : v)
        cout << ((i - Q + K <= 0) ? "No\n" : "Yes\n");
}

Measured memory_bytes: 1024
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

S = gets.chomp
K = get_int

strs = S.split('')

set = SortedSet.new
strs.each { |s| set.add(s) }

count_set = SortedSet.new
sorted_strs = set.to_a

ans = nil

sorted_strs.each do |start_char|
  indexes = []
  strs.each.with_index do |s, i|
    if s == start_char
      indexes << i
    end
  end
  indexes.each do |i|
    ([strs.length - i, K].min).times do |j|
      count_set.add(S[i..(i+j)])
    end
  end
  if count_set.length >= K
    ans = count_set.to_a[K-1]
    break
  end
end

puts ans


Measured memory_bytes: 14752
#include <bits/stdc++.h>
#include <string>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
  int cost = 0;
  int x=0;
  for(int i=0;i<N;i++){
    cin >> x;
    if(x<=(K/2)){
      cost += (2*x);
    }else{
      cost += (2*(K-x));
    }
      }
      cout << cost << endl;
      }
      

Measured memory_bytes: 256
n,m=map(int,input().split())
a=[0]*n
a[0]=1
b=[1]*n
for i in range(m):
  x,y=map(int,input().split())
  if(a[x-1]==1):
    a[y-1]=1
  b[x-1] -= 1
  b[y-1] += 1
  if(b[x-1]==0):
    a[x-1]=0
print(sum(a))

Measured memory_bytes: 4596
/*
** author:mahmoud magdy
*/
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"

inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m;
    cin>>m;
    return m;
}
void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

int main()
{
    fast();
    string s;
    cin>>s;
    for(int i=0;i<s.length();++i)cout<<"x";
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <limits>

using namespace std;

int n;
vector<vector<int> > timet;
vector<vector<int> > gain;

// k == 0: gozen, k == 1: gogo
bool is_open(int store, int day, bool k) {
  int a = timet[store][day];
  if(k == 0)
    return a / 10 == 1;
  else
    return a % 10 == 1;
}

int total_gain(int bit) {
  int day = 0;
  int b = bit;
  vector<int> count(n, 0);
  while(bit != 0) {
    bool gozen = ((bit >> 1) & 1) == 1;
    bool gogo = (bit & 1) == 1;
    if(gozen || gogo) {
      for(int i = 0; i < n; i++) {
        if(gozen && is_open(i, day, 0))
          count[i]++;
        if(gogo && is_open(i, day, 1))
          count[i]++;
      }
    }
    bit = bit >> 2;
    day++;
  }
  int r = 0;
  for(int i = 0; i < n; i++) {
    int c = count[i];
    r += gain[i][c];
  }
  return r;
}

int calc() {
  int n = 0;
  int m = 1 << 10;
  int max = INT_MIN;
  for(int i = 1; i < m; i++) {
    int gain = total_gain(i);
    max = max < gain ? gain : max;
  }
  return max;
}

int main() {
  cin >> n;
  timet.resize(n);
  for(int i = 0; i < n; i++) {
    timet[i].resize(5);
    for(int j = 0; j < 5; j++) {
      int gozen, gogo;
      cin >> gozen;
      cin >> gogo;
      timet[i][j] = gozen * 10 + gogo;
    }
  }
  gain.resize(n);
  for(int i = 0; i < n; i++) {
    gain[i].resize(11);
    for(int j = 0; j < 11; j++) {
      cin >> gain[i][j];
    }
  }
  std::cout << calc();
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		String str = sca.next();
		int length = str.length();
		boolean flag = true;

		for(int i = 0; i < (length-1)/2; i++) {
			if(str.charAt(i) != str.charAt(length-i-1)) {
				flag = false;
			}
		}

		for(int i = 0; i < (length-1)/2; i++) {
			if(str.charAt(i) != str.charAt((length-1)/2 - 1 - i)) {
				flag = false;
			}
		}

		for(int i = 0; i < (length-1)/2; i++) {
			if(str.charAt((length+3)/2-1 + i) != str.charAt(length - 1 - i)) {
				flag = false;
			}
		}

		if(flag == true) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}

		// 後始末
		sca.close();
	}
}

Measured memory_bytes: 22612
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define answer(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    cout << 6 - a - b << endl;

    return 0;
}

Measured memory_bytes: 256
import itertools
import math

n=int(input())
lis=[i for i in range(n)]
P_lis=itertools.permutations(lis)

x=[0]*n
y=[0]*n
for i in range(n):
  x[i],y[i]=map(int,input().split())

ans=0
P=list(P_lis)
for i in range(len(P)):
  for j in range(n-1):
    ans+=math.sqrt((x[P[i][j]]-x[P[i][j+1]])**2+(y[P[i][j]]-y[P[i][j+1]])**2)
print(ans/len(P))

Measured memory_bytes: 7972
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n;
    ll x;
    cin >> n >> x;
    
    vector<ll> v(n);
    for(ll& i : v) cin >> i;

    ll ans = 0;
    REP(i, n-1){
        ll a = max(0LL, v[i] + v[i+1] - x);
        v[i+1] = max(0LL, v[i+1] - a);
        ans += a;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1152
#include <cstdio>

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

  int res = 0;
  for (int X = 0; X <= K; ++X)
    for (int Y = 0; Y <= K; ++Y) {
      int Z = S-(X+Y);
      if (0 <= Z && Z <= K) ++res;
    }

  printf("%d\n", res);
}

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

#define int long long

const int N = 2e2 + 10;
int n, l;

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> l;
	int mx = (int)-1e18, mn = (int)1e18;
	for (int i = 0; i < n; i++) {
		int tot = n * l + (n * (n - 1)) / 2, now = l + i;
		if (abs(now) < mn)
			mn = abs(now), mx = tot - now;
	}
	cout << mx << endl;
}

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

#define X first
#define Y second
typedef long long ll;
typedef pair<ll,ll> pll;

int main(int argc, char const *argv[])
{
    //ios::sync_with_stdio(false);
    //cin.tie(NULL);
    ll a;
    cin >> a;
    cout << 180*(a-2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<int,int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI  = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const int INF = 1 << 30;
// static const ll INF = 1LL << 62;
// --------------------------------------------------------


bool is_prime(int N) {
    if (N == 1) return false;
    if (N == 2) return true;
    if (N % 2 == 0) return false;
    double root_n = sqrt(N) + 0.5;
    int f = 3;
    while (f <= root_n) {
        if (N % f == 0) return false;
        else f += 2;
    }
    return true;
}


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

    int Q; cin >> Q;

    static const int MAX_N = 1e+5;
    VB is_like_2017(MAX_N + 1, false);
    for (int i = 1; i <= MAX_N; i += 2) {
        if (is_prime(i) && is_prime((i + 1) / 2)) {
            is_like_2017[i] = true;
        }
    }

    VI S(MAX_N + 1, 0);
    FOR(i, 1, MAX_N + 1) S[i] = S[i - 1] + is_like_2017[i];

    REP(_, Q) {
        int l, r; cin >> l >> r;
        cout << S[r] - S[l - 1] << '\n';
    }

    return 0;
}


Measured memory_bytes: 3680
def main():
	# n,k = map(int,input().split())
	n = int(input())
	# s = str(input())
	h = list(map(int,input().split()))
	# l = [list(map(int, input().split())) for _ in range(n)]
	# s = list(s)
	
	from fractions import gcd

	ans = h[0]
	for i in range(1,n):
		ans = gcd(ans,h[i])
	print(ans)


if __name__ == '__main__':
	main()

Measured memory_bytes: 81684
#include<bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define whole(v) begin(v),end(v)
#define print(c,n) for(int i=0;i<n;i++) cout << c[i] << " ";
#define MOD 1000000007
#define INF 0x3f3f3f3f
int a[100005],dp[100005];
int main()
{
	
   	std::ios::sync_with_stdio(false);
	cin.tie(0);
   	int n;
   	cin >> n;
   	for(int i=0;i<n;i++) cin >> a[i];
   	dp[0] = 0;
   	dp[1] = abs(a[1]-a[0]);
   	dp[2] = min(dp[1]+abs(a[2]-a[1]),abs(a[2]-a[0]));
   	for(int i=3;i<n;i++){
   		dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
   	}
   	cout << dp[n-1] << "\n";
   	return 0;
}

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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}

void solve(){


}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	int n,m,v,p;cin>>n>>m>>v>>p;
	vi a(n);
	rep(i,n) cin>>a[i];
	sort(all(a));
	reverse(all(a));
	int ans = p;
	ll pf = a[p-1];
	repA(i,p,n-1){
		if(a[i]+m<a[p-1]){}
		else if(v<=n-i+p-1) ans++;
		else{
			ll rq = 1ll*(v-(n-i+p-1))*m;
			ll cur = 1ll*(i-(p-1))*(a[i]+m) - pf;
			if(cur>=rq) ans++;
		}
		pf+=a[i];
	}
	cout<<ans;	
	
	return 0;
}



Measured memory_bytes: 640
X, Y, Z, K = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

ab_items = []
for a in a_list:
    for b in b_list:
        ab_items.append(a + b)

ab_items.sort(reverse=True)
ab_items = ab_items[:K + 1]

ans = []
for c in c_list:
    for ab in ab_items:
        ans.append(c + ab)

ans.sort(reverse=True)

for i in range(K):
    print(ans[i])


Measured memory_bytes: 141764
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
  int a[5];
  rep(i,5) cin >> a[i];
  int sum = 0;
  rep(i,5) sum += a[i];
  
  int b[5];
  rep(i,5){
    if(a[i] % 10 == 0) b[i] = 0;
    else b[i] = 10- (a[i] % 10);
  }
    
  rep(i,5) sum += b[i];
  sort(b, b+5, greater<int>());
  sum = sum - b[0];
  
  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 256
def f(n):
  if n%2==0:
    return n//2
  else:
    return 3*n+1
  
ans=[]
s=int(input())
for i in range(2,1000001):
  ans.append(s)
  if f(s) in ans:
    print(i)
    break
  else:
    s=f(s)
      

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;
	cout << max(A + B, max(A - B, A * B)) << endl;

	return 0;
}

Measured memory_bytes: 256
#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

def main():
  n,a,b=map(int,input().split())
  mod=10**9+7
  cmb_l=[1 for _ in range(b+1)]
  for i in range(b):
    cmb_l[i+1]=(cmb_l[i]*(n-i)%mod*mod_inv(i+1,mod))%mod

  x=cmb_l[a]
  y=cmb_l[b]
  return((2**n-x-y-1) % mod)
print(main())

Measured memory_bytes: 286504
inputint = list(map(int,input().split()))

a = inputint[0] + inputint[1] + 1
b = inputint[2]
result = 0
if a >= b:
    result = inputint[1] + b
elif a < b:
    result = inputint[1]*2 + inputint[0] + 1

print(result)

Measured memory_bytes: 3060
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

int main() {
	int i, j, k;
	int n;
	string s;

	cin >> n >> s;

	int cnt = 0, mcnt = 0;

	for (i = 0; i < n; i++) {
		if (s[i] == 'E') {
			cnt--;
		}
		//else if (s[i] == 'W') {
		//	cnt++;
		//}
	}

	mcnt = cnt;
	int index = 0;
	for (i = 1; i < n; i++) {
		if (s[i - 1] == 'E') {
			cnt++;
		}
		else if (s[i - 1] == 'W') {
			cnt--;
		}
		//mcnt = max(mcnt, cnt);
		if (mcnt < cnt) {
			mcnt = cnt;
			index = i;
		}
	}

	int cnt3 = 0;

	for (i = index - 1; i >= 0; i--) {
		if (s[i] == 'W') {
			cnt3++;
		}
	}

	for (i = index + 1; i < n; i++) {
		if (s[i] == 'E') {
			cnt3++;
		}
	}


	cout << cnt3 << endl;














	getchar();
	getchar();
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<ll> L(N+1);
  L.at(0) = 2ll;
  L.at(1) = 1ll;
  for (int i = 2; i <= N; i++) {
    L.at(i) = L.at(i-1) + L.at(i-2);
  }
  
  cout << L.at(N) << endl;
}

Measured memory_bytes: 256
import os
import sys

import numpy as np


def solve(inp):
    n = inp[0]
    xxx = inp[1::3]
    yyy = inp[2::3]
    ppp = inp[3::3]

    ans = np.full(n + 1, 10 ** 18, dtype=np.int64)

    default_dist = np.zeros(n, dtype=np.int64)
    for i in range(n):
        default_dist[i] = min(abs(xxx[i]), abs(yyy[i]))

    for bit in range(1 << n):
        k = (bit & 0x5555) + (bit >> 1 & 0x5555)
        k = (k & 0x3333) + (k >> 2 & 0x3333)
        k = (k & 0x0f0f) + (k >> 4 & 0x0f0f)
        k = (k & 0x00ff) + (k >> 8 & 0x00ff)

        i = 0
        cur = 0
        t = bit
        selected = np.zeros(k, dtype=np.int64)
        is_selected = np.zeros(n, dtype=np.int8)
        while t:
            if t & 1:
                selected[cur] = i
                is_selected[i] = 1
                cur += 1
            t >>= 1
            i += 1

        for bit2 in range(1 << k):
            cost = 0
            for i in range(n):
                if is_selected[i]:
                    continue
                town_dist = default_dist[i]
                t = bit2
                for j in range(k):
                    if t & 1:
                        town_dist = min(town_dist, abs(yyy[selected[j]] - yyy[i]))
                    else:
                        town_dist = min(town_dist, abs(xxx[selected[j]] - xxx[i]))
                    t >>= 1
                cost += town_dist * ppp[i]
            kk = len(selected)
            ans[kk] = min(ans[kk], cost)

    return ans


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8[:],)', cache=True)(solve)
    print('compiled', file=sys.stderr)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print('\n'.join(map(str, ans)))

Measured memory_bytes: 27404
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
int main(void){
    int n, s = 0;
    P p[200000];
    cin >> n;
    for(int i=0;i<n;i++){
        int a, b;
        cin >> a >> b;
        p[i] = P(b, a);
    }
    sort(p, p+n);
    for(int i=0;i<n;i++){
        s += p[i].second;
        if(s > p[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


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

typedef long long ll;
#define MAXN 100005
#define MOD 998244353
const int INF = 1e9 + 5;

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

    int A,B;
    cin >> A >> B;
    for(int price = 1 ; price <= 1250 ; price++){
        if((int)(price * (0.08)) == A && (int)(price * (0.1)) == B){
            cout << price << '\n';
            return 0;
        }
    }
    cout << -1 << '\n';

    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

increase = True
equal = True
start = True
count = 1

for i, a in enumerate(A):
    if i > 0:
        if equal:
            if a > A[i-1]:
                increase = True
                equal = False
            elif a < A[i-1]:
                increase = False
                equal = False
        else:
            if increase:
                if a < A[i-1]:
                    count += 1
                    equal = True
                    # print(i)
            else:
                if a > A[i-1]:
                    count += 1
                    equal = True
                    start = True
                    # print(i)

print(count)


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

int main() {
    int64_t n, k, s;
    cin >> n >> k;
    s = 0;
    vector<int> vec(n);

    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }

    sort(vec.begin(), vec.end());

    if (n <= k) {
        cout << s << endl;
    }
    else {
        for(int j = 0; j < n-k; j++) {
            s += vec.at(j); 
        }
        cout << s << endl;
    }
    
}

Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;



int main(){
    
    int N,s[200020],now;
    cin>>N;
    if(N%2==0){
        now=N/2;
        rep(i,0,N){
            now+=pow(-1,i)*i;
            cin>>s[now];
            
        }
    }
    else if(N%2==1){
        now=N/2;
        rep(i,0,N){
            now+=pow(-1,i+1)*i;
            cin>>s[now];
            
        }
    }
    rep(i,0,N){
        cout<<s[i];
        if(i!=N-1)cout<<" ";
    }
    cout<<endl;
}






Measured memory_bytes: 2944
a, b = map(int, input().split())
d = {1:1, 3:1, 5:1, 7:1, 8:1, 10:1, 12:1, 4:2, 6:2, 9:2, 11:2, 2:3}
if d[a] == d[b]:
  print('Yes')
else:
  print('No')

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

int main()
{
  string S;

  cin >> S;

  int cnt = 0;

  for (int i = 0; i < S.length() / 2; i++)
  {
    if (S[i] != S[S.length() - i - 1])
    {
      cnt++;
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main(){
  int len,ans=114514810,num;
  char s[10];
  cin >> s;
  for(len=0;s[len]!='\0';len++){}
  for(int i=0;i<len-2;i++){
    num = (s[i] - '0')*100+(s[i+1] - '0')*10+(s[i+2] - '0');
    ans = min(ans,abs(num-753));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)

#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


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 powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i= 0; i <b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}


int main(){
	int i, j, k;

	int N, M, K;

	cin >> N;
	vector<int> c;
	vector<int> A[10001];
	int B[10001] = { 0 };
	rep(i, 0, N - 1) {
		int a, b;
		cin >> a >> b;
		A[a].push_back(b);
		A[b].push_back(a);
	}
	ll sum = 0;
	rep(i, 0, N) {
		int a;
		cin >> a;
		sum += a;
		c.push_back(a);
	}
	sort(c.rbegin(), c.rend());
	sum -= c[0];

	stack<int> Q;
	Q.push(1);
	B[1] = c[0];
	for (i = 1; i < N;) {
		int x = Q.top();
		Q.pop();
		for (auto y : A[x]) {
			if (B[y] != 0)
				continue;

			B[y] = c[i++];
			Q.push(y);

		}


	}
	cout << sum << endl;
	rep(i, 1, N + 1) {
		cout << B[i] << " ";
	}
	return 0;
}

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

int main() {
	int n,buf;
	int max;
	vector<int> h;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> buf;
		h.emplace_back(buf);
	}
	max = h[0];
	for (int j = 1; j < n; j++) {
		if (max < h[j]) {
			max = h[j];
		}
		if (max - h[j] > 1) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N,M;
    cin>>N>>M;
    vint X(N+1);rep(i,N)cin>>X[i+1];
    int ans=0;
    for(int i=1;i<=N;i++){
        int t=X[i]+X[i-1];
        if(t>M){
            t-=M;
            int s=min(t,X[i]);
            X[i]-=s;
            ans+=s;
            t-=s;
            X[i-1]-=t;
            ans+=t;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  string s,t;
  cin >> s;
  cin >> t;
  s="0"+s;
  t="1"+t;
  int ss=s.size(),ts=t.size();
  int dp[ss][ts];
  int i,j;
  for(i=0;i<ss;i++)dp[i][0]=0;
  for(i=0;i<ts;i++)dp[0][i]=0;
  for(i=1;i<ss;i++){
    for(j=1;j<ts;j++){
      if(s[i]==t[j])dp[i][j]=dp[i-1][j-1]+1;
      else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
    }
  }
  i--;
  j--;
  string ret="";
  while(i>0 && j>0){
    if(dp[i][j]==dp[i-1][j])i--;
    else if(dp[i][j]==dp[i][j-1])j--;
    else if(dp[i][j]==dp[i-1][j-1]+1){
      ret+=s[i];
      i--;
      j--;
    }
  }
  reverse(ret.begin(),ret.end());
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 35456
h, w = gets.split.map(&:to_i)
c = Hash.new 0
h.times.map {
  gets.chomp.each_char{|a|
    c[a] += 1
  }
}
res = nil
c = c.values
b = c.all?{|x| x % 4 == 0}
m1 = c.count{|x| x.odd?}
m2 = c.select{|x| x % 4 != 0 && x.even?}.size
res = b


if h.odd? && w.odd?
  if m1 != 1
    res = false
  else
    n = w / 2 + h / 2
    if !b
      res = n >= m2
    end
  end

elsif h.odd?
  n = w / 2
  if !m1.zero?
    res = false
  else
    if !b
      res = n >= m2
    end
  end
elsif w.odd?
  n = h / 2
  if !m1.zero?
    res = false
  else
    if !b
      res = n >= m2
    end
  end
else
end

puts res ? :Yes : :No

Measured memory_bytes: 1788
s = input()

s_1=s[:((len(s)-1)//2)]
s_2=s[((len(s)+3)//2)-1:]
#print(s_1)
#print(s_2)

flag = True

for a in range(len(s)//2):
    if s[a] != s[-(a+1)]:
        flag =False

for a in range(len(s_1)//2):
    if s_1[a] != s_1[-(a+1)]:
        flag =False

for a in range(len(s_2)//2):
    if s_2[a] != s_2[-(a+1)]:
        flag =False

if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9156
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
#include<string>
#include<iomanip>
#include<map>
#include<fstream>
#include<queue>
#include<set>
#include<deque>

using namespace std;

int main()
{
	string s;
	cin >> s;
	int y, m, d;
	y = stoi(s.substr(0, 4));
	m = stoi(s.substr(5, 2));
	d = stoi(s.substr(8, 2));
	if (y < 2019)
		cout << "Heisei" << endl;
	else if (m <= 4)
		cout << "Heisei" << endl;
	else
		cout << "TBD" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;

bool pal(string a)
{
    string b(a.rbegin(), a.rend());
    return a == b;
}

int main()
{
    string a;
    cin >> a;
    int n = a.size();

    cout << (pal(a) and pal(a.substr(0, (n - 1) / 2)) and pal(a.substr(((n + 3) / 2) - 1, n)) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;

int main(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); 
	 
	string c1, c2, c3; cin >> c1 >> c2 >> c3; int i = 0;
	cout << c1[0]<< c2[1] << c3[2] << endl;
	return 0;
}




Measured memory_bytes: 3612
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#define fileoutput ofstream f;f.open("output.txt");if(!f.is_open()){cout<<"faild";return 0;}cout.rdbuf(f.rdbuf());
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define mod 1000000007
#define inf 2e9
#define sz 1005
using namespace std;

ll fact[1005], inv[1005];

ll fp(ll base, ll exp)
{
    if (exp == 0)
        return 1;
    ll ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}

void calc()
{
    fact[0] = inv[0] = 1;
    for (ll i = 1; i <= 1000; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = fp(fact[i], mod - 2);
    }
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

int main()
{
    calc();
    ll n, m, ans = 0;
    cin >> n >> m;
    if (n >= 2)ans += ncr(n, 2);
    if (m >= 2)ans += ncr(m, 2);
    cout << ans << endl;
	return 0;
}

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

#define ll long long int
#define str string
#define ALL(a)  (a).begin(),(a).end()
#define P pair<double,ll>

using Graph = vector<vector<int>>;

const int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
ll INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Min = INFL, Max = -1;
ll a, b, c, n, sum, A[500010], B[500000], dp[5000];
str S[200010]; bool check = true;	vector<ll> v;



int main() {
	//Code Line
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	for (int i = -100; i < 100; i++) {
		sum = 0;
		for (int j = 0; j < n; j++) {
			
			b = A[j]-i;
			sum += b * b;
		}
		Min = min(Min, sum);
	}
	cout << Min << endl;

	return 0;
}


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

#define temptts template <class T, class... Ts>
temptts int add(T f) { return f; } temptts int add(T f, Ts... ts) { return (f + add(ts...)) % mod; }
temptts int sub(T f) { return f; } temptts int sub(T f, Ts... ts) { return (f - sub(ts...) + 1ll * mod * mod) % mod; }
temptts int mul(T f) { return f; } temptts int mul(T f, Ts... ts) { return (1ll * f * mul(ts...)) % mod; }
int binpow(ll n, ll k) { int ans = 1; while (k) { if (k & 1) ans = mul(ans, n); n = mul(n, n), k >>= 1; } return ans; }
ll powr(ll x, int k) { ll res = 1; while (k) { if (k & 1) { if (x && mod / x < res) return 0; res = res * x; } if (x && mod / x < x) x = 0; x = x * x; k >>= 1; } return res; }
int inv(int n) { return binpow(n, mod - 2); }
struct precompute { int f[N]; precompute() { f[0] = 1; for (int i = 1; i < N; i++) f[i] = mul(f[i - 1], i); } int operator() (int n) { return f[n]; } } fact;
int C(int n, int k) { return mul(fact(n), inv(mul(fact(k), fact(n - k)))); }

struct edge {
  int u, v;
  ll w;
  bool operator < (const edge &o) const {
    return w > o.w;
  }
} e[N];

int n, m, s, t;
bool vis[N];
ll ds[N], dt[N];
int cs[N], ct[N];
vector<int> adj[N];

void dijkstra(int s, ll* d, int* c) {
  priority_queue<edge> pq;
  for (int i = 1; i <= n; i++) {
    d[i] = 1e18;
    vis[i] = 0;
  }
  pq.push({s, s, d[s] = 0});
  c[s] = 1;
  while (!pq.empty()) {
    int v = pq.top().v;
    pq.pop();
    if (vis[v]) continue;
    vis[v] = 1;
    for (auto& i : adj[v]) {
      int u = v ^ e[i].u ^ e[i].v;
      ll w = e[i].w;
      if (d[v] < 1e18 && d[u] > d[v] + w) {
        c[u] = c[v];
        pq.push({v, u, d[u] = d[v] + w});
      } else if (d[u] == d[v] + w) {
        c[u] = add(c[u], c[v]);
      }
    }
  }
}

int32_t main() { cin.tie(0)->sync_with_stdio(0);
  cin >> n >> m >> s >> t;
  for (int i = 1, u, v, w; i <= m; i++) {
    cin >> u >> v >> w;
    e[i] = {u, v, w};
    adj[u].push_back(i);
    adj[v].push_back(i);
  }
  dijkstra(s, ds, cs);
  dijkstra(t, dt, ct);
  ll ans = 0;
  for (int v = 1; v <= n; v++) {
    if (ds[v] + dt[v] == ds[t] 
    && 2 * ds[v] == ds[t] 
    && 2 * dt[v] == dt[s]) {
      ll cc = mul(cs[v], ct[v]);
      ans = add(ans, mul(cc, cc));
    }
  }
  for (int i = 1; i <= m; i++) {
    int u = e[i].u, v = e[i].v;
    ll w = e[i].w;
    if (ds[u] + dt[v] + w == ds[t] 
    && 2 * ds[u] < ds[t] 
    && 2 * dt[v] < dt[s]) {
      ll cc = mul(cs[u], ct[v]);
      ans = add(ans, mul(cc, cc));
    }
    if (ds[v] + dt[u] + w == ds[t] 
    && 2 * ds[v] < ds[t] 
    && 2 * dt[u] < dt[s]) {
      ll cc = mul(cs[v], ct[u]);
      ans = add(ans, mul(cc, cc));
    }
  }
  cout << sub(mul(cs[t], ct[s]), ans);
}

Measured memory_bytes: 21692
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tok = new StringTokenizer(br.readLine());
        final int h = Integer.parseInt(tok.nextToken());
        final int w = Integer.parseInt(tok.nextToken());
        char[][] mat = new char[h][w];
        boolean[] colVisible = new boolean[w];

        // 読み込み
        int cnt = 0;
        boolean flag;
        String row;
        char c;
        for (int i = 0; i < h; i++) {
            flag = false;
            row = br.readLine();
            for (int j = 0; j < w; j++) {
                c = row.charAt(j);
                mat[cnt][j] = c;
                if (c == '#') {
                    flag = true;
                    colVisible[j] = true;
                }
            }
            if (flag) cnt++;
        }
        // 表示
        for (int i = 0; i < cnt; i++) {
            for (int j = 0; j < w; j++) {
                if (colVisible[j])
                    System.out.print(mat[i][j]);
            }
            System.out.print("\n");
        }
    }
}


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

namespace ABC089A
{
    class Program
    {
        static void Main(string[] args)
        {
            int N;

            N = int.Parse(Console.ReadLine());

            Console.WriteLine(N / 3);

            Console.ReadKey();

        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
ll n,ans;
int main(void){
    cin>>s;
    n=s.size();
    for(int i=0;i<n/2;i++){
        if(s[i]!=s[n-i-1])ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))

def binary_search(lst, n, val):
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if lst[mid] == val:
            return True
        elif lst[mid] < val:
            left = mid + 1
        elif lst[mid] > val:
            right = mid
    return False

ans = 0
for val in t:
    if binary_search(s, n, val):
        ans += 1

print(ans)



Measured memory_bytes: 16712
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<bitset>
#include<functional>
#include<climits>
using namespace std;
typedef pair<int,int>pii;
const int INF=1e9;
const int dx[]={0,-1,0,1},dy[]={-1,0,1,0};

struct data{
    int cnt,m,id;
    data(int a,int b,int c):cnt(a),m(b),id(c){}
    data(){}
    bool operator<(const data &d)const{
        if(cnt!=d.cnt)return cnt<d.cnt;
        if(m!=d.m)return m>d.m;
        return id>d.id;
    }
};

int main(){
    int t,p,r;
    while(cin>>t>>p>>r,t||p||r){
        bool ac[50][10];fill_n(*ac,500,false);
        int wa[50][10];fill_n(*wa,500,0);
        vector<data>D(t);
        for(int i=0;i<t;i++){
            D[i]=data(0,0,i);
        }
        while(r--){
            int tid,pid,tm;
            string mes;
            cin>>tid>>pid>>tm>>mes;
            tid--;
            pid--;
            if(ac[tid][pid])continue;
            if(mes=="CORRECT"){
                ac[tid][pid]=true;
                D[tid].cnt++;
                D[tid].m+=tm+1200*wa[tid][pid];
            }
            else wa[tid][pid]++;
        }
        sort(D.rbegin(),D.rend());
        for(int i=0;i<t;i++){
            data x=D[i];
            cout<<x.id+1<<" "<<x.cnt<<" "<<x.m<<endl;
        }
    }
    return 0;
}

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

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

	int64_t ac=(int64_t)a*c;
	int64_t ad=(int64_t)a*d;
	int64_t bc=(int64_t)b*c;
	int64_t bd=(int64_t)b*d;

	int64_t largest=max(ac,ad);
	largest=max(largest,bc);
	largest=max(largest,bd);
	cout << largest << endl;
}

	


Measured memory_bytes: 3628