akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const ll LINF = 1LL << 50;
const int MAX = 1e+3 + 5;
const int NIL = -1;
const int WALL = 0;
const int ROOT = 1;
const int mod = 1e+9 + 7;
/* global variables */
int H, W;
vector<vector<int>> G(MAX, vector<int>(MAX, WALL));
vector<vector<ll>> dp(MAX, vector<ll>(MAX, 0));
/* function */
void input() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        string S;
        cin >> S;
        for (int j = 0; j < W; j++)
            G[i][j] = (S[j] == '.' ? ROOT : WALL);
    }
}
void calcDPTable() {
    dp[0][0] = 1;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (G[i+1][j] == ROOT) {
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= mod;
            }
            if (G[i][j+1] == ROOT) {
                dp[i][j+1] += dp[i][j];
                dp[i][j+1] %= mod;
            }
        }
    }
}
void printAns() { cout << dp[H-1][W-1] << '\n'; }
/* main */
int main(){
    input();
    calcDPTable();
    printAns();
}


Measured memory_bytes: 15512
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1147&lang=jp

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    while (true) {
        cin >> n;
        if (n == 0) return 0;

        vector<int> vt(n);
        for (int i = 0; i < n; ++i) {
            cin >> vt[i];
        }
        
        sort(vt.begin(), vt.end());
        cout << accumulate(vt.begin() + 1, vt.end() - 1, 0) / (n - 2) << endl;
    }
}


/*
 *
 */


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

int main()
{
ll n , m ;
cin >> n >> m ;
string s ;
cin >> s ;
vector<ll> ans;
ll now=n;
while(1){
  bool b=0;
  for(ll i=m;i>0;i--){
    if(now-i>=0&&s[now-i]=='0'){
      b=1;
      ans.push_back(i);
      now=now-i;
      break;
    }
  }
  if(b==0){
    cout << -1 << endl;
    return 0;
  }
  if(now==0)break;
}
reverse(ans.begin(),ans.end());
for(auto an:ans)cout << an << ' ';
cout << endl;
return 0;
}

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

const int MAXN = 200000 + 10;

int n;
int a[MAXN];
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin >> n;

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

    int s2 = a[0];
    int best = 100000LL;
    best *= best * best;
    
    for (int i = 1; i < n; i++) {
        best = min(best, abs(s2 - (s-s2)));
        s2 += a[i];

    }

    cout << best << "\n";
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o set

signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    string s; cin >> s;
    string ss="CODEFESTIVAL2016";
    int cnt=0;
    rep(i,s.size()){
        if(s[i]!=ss[i]) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3648
/**
*Coder: Yeshayah
**/

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int k;
    string s;
    cin >> k >> s;
    if (s.size() <= k) cout << s << "\n";
    else cout << s.substr(0,k) << "...\n";
    return 0;
}

Measured memory_bytes: 3624
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.Unboxed            as AU
import qualified Data.Array.ST                 as ST
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
readInts n = replicateM n readInt
readString = map BS.unpack . BS.words <$> BS.getLine
readStrings n = replicateM n $ BS.unpack <$> BS.getLine
toPair [x, y] = (x, y)

main = do
  [n, m] <- readInt
  sc     <- map toPair <$> readInts m
  print $ solve sc n

solve sc n = head $ g nums sc ++ [-1]
  where nums = if n == 1 then [0 .. 9] else [10 ^ (n - 1) .. (10 ^ n) - 1]

f num s c = ((\x -> read $ x : "") $ show num !! (s - 1)) == c

g nums sc = filter (\num -> all ((== True) . (\(s, c) -> f num s c)) sc) nums


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    int r;
    cin  >> r;
    cout << r*r << endl;
}

Measured memory_bytes: 3644
fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n: i64 = read()[0];
    let a: Vec<i64> = read();
    for i in 0..n {
        if i != 0 {
            print!(" ");
        }
        let idx = std::cmp::max(n - i * 2 - 1, i * 2 - n) as usize;
        print!("{}", a[idx]);
    }
    println!("");
}


Measured memory_bytes: 10492
import java.util.Scanner;
public class Main {

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

		Scanner sc = new Scanner(System.in);

		int p = sc.nextInt();
		int q = sc.nextInt();
		int r = sc.nextInt();
		int max = 0;
		int sum = p + q + r;
        int[] data = {p, q, r};
        // 最大値を求める
        for(int i = 0; i < data.length; i++)
                max = Math.max(max,data[i]);
		System.out.println(sum - max);


	}

}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
typedef pair<double, double> P;
int main() {
    int n;
    cin >> n;
	vector<queue<int>> q(n+1);
	for (int i=0;i<n; i++){
		for (int j=0;j<n-1;j++){
			int x;
			cin>>x;
			q[i].push(x-1);
		}
		q[i].push(n);
	}
	q[n].push(n);
	int ans=0;
	int cnt=n*(n-1);
	int f=1;
	vector<int>update;
	for (int i=0;i<n;i++){
		update.push_back(i);
	}
	while (cnt > 0){
		ans++;
		vector<int>update2;	
		for (int i : update){
			if (q[q[i].front()].front()==i && q[i].front()>i){
				update2.push_back(i);
				update2.push_back(q[i].front());
			}
		}
		for (int i:update2){
			q[i].pop();
			cnt--;
		}
		if (update2.empty()){
			f=0;
			break;
		}
	}
	if(f==0) cout<<-1<<endl;
	else cout<<ans<<endl;
}



Measured memory_bytes: 8056
#include<iostream>
using namespace std;
int n;
int a[2<<17];
long ans=0;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=n;i--;)
	{
		if(a[i]>i||i<n-1&&a[i]+1<a[i+1])
		{
			cout<<-1<<endl;
			return 0;
		}
		else if(i<n-1&&a[i]+1==a[i+1])continue;
		else ans+=a[i];
	}
	cout<<ans<<endl;
}


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

int main() {
	int N, M;
	cin >> N >> M;
	vector<pair<int, int>> s_c(M);
	for (int i = 0; i < M; i++) {
		cin >> s_c.at(i).first >> s_c.at(i).second;
	}
	char S[N + 1];
	for (int i = 0; i < N; i++) {
		S[i] = 'a';
	}
	S[N] = '\0';

	for (int i = 0; i < M; i++) {
		int point, number;
		tie(point, number) = s_c.at(i);
		if (point > N) {
			cout << "-1" << endl;
			return 0;
		}
		if (point == 1 && number == 0 && N != 1) {
			cout << "-1" << endl;
			return 0;
		}
		if (S[point - 1] == 'a' || S[point - 1] == number + '0') {
			S[point - 1] = number + '0';
		} else {
			cout << "-1" << endl;
			return 0;
		}
	}

	for (int i = 0; i < N; i++) {
		if (S[i] == 'a' && i == 0 && N != 1) S[i] = '1';
		if (S[i] == 'a' && i == 0 && N == 1) S[i] = '0';
		if (S[i] == 'a') S[i] = '0';
	}
	int ans = atoi(S);
	cout << ans << endl;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#define rep(i,a,b) for(int i=(a),i##ed=(b);i<=i##ed;i++)
#define per(i,a,b) for(int i=(a),i##ed=(b);i>=i##ed;i--)
using namespace std;
const int N=300010;
int n,m,sum,pos,res;
int t[N];
struct P {
	int x,y;
	inline bool operator<(const P &yy)const { return y-x<yy.y-yy.x; }
};P a[N];

inline void add(int x,int w) { for(;x<=m;x+=x&-x) t[x]+=w; }
inline int ask(int x) { int s=0;for(;x;x-=x&-x) s+=t[x];return s; }
int main() {
	scanf("%d%d",&n,&m),sum=n,pos=1;
	rep(i,1,n) scanf("%d%d",&a[i].x,&a[i].y);
	sort(a+1,a+n+1);
	rep(i,1,m) {
		for(;a[pos].y-a[pos].x+1<i&&pos<=n;)
			add(a[pos].x,1),add(a[pos].y+1,-1),++pos,--sum;
		res=0; rep(j,1,m/i) res+=ask(j*i);
		printf("%d\n",res+sum);
	}
	return 0;
}

Measured memory_bytes: 3584
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        int x,a,b,c;
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        x = sc.nextInt();
        int cnt=0;
        for(int i=0;i<=a;i++)
        {
            for(int j=0;j<=b;j++){
                int sum = i*500+j*100;
                if(sum==x)cnt++;
                else if(x>sum&&(x-sum)%50==0&&(x-sum)/50<=c)cnt++;
            }
        }
        
        System.out.println(cnt);
        
    }
}

Measured memory_bytes: 20940
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife
	
	int n;
	cin >> n;
	vector<int> arr(n);
	int ans = 0;
	for(int i = 0; i < n; i++)
		cin >> arr[i];
	for(int i = 0; i < n; i++)
		for(int j = 0; j < i; j++)
			for(int k = 0; k < j; k++)
				if(arr[i]!=arr[j]&&arr[j]!=arr[k]&&arr[k]!=arr[i] && arr[i]+arr[j]+arr[k]-2*max({arr[i],arr[j],arr[k]}) > 0)
					ans++;
	cout << ans << '\n';

		return 0;
}


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

int main(){
  int D, T, S;
  cin >>D >>T >>S;
  
  double need_time = (double)D / S;
  
  if (need_time <= T) {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
ll gcd(ll a, ll b){
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}
ll lcm(ll a, ll b){
    if (a > b) return a / gcd(a, b) * b;
    else return b / gcd(a, b) * a;
}
int main(){
    ll a, b, c, d;
    scll(a), scll(b), scll(c), scll(d);
    ll ans = b/c + b/d - b/lcm(c, d);
    ans -= (a-1)/c + (a-1)/d - (a-1)/lcm(c,d);
    cout << b - a + 1 - ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
 
#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);
 
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;
 
constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;
 
template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}


int main() {
	ll N; cin >> N;
	corner(N%2,0);
	N /= 10;
	N *= 10;
	ll sum = 0;

	for(ll i = 1; i <= 60; ++i){
		ll M = N;
		for(int j = 0; j < i; ++j){
			M /= 5;
		}
		sum += M/2;
	}
	cout << sum << endl;





	return 0;

}


Measured memory_bytes: 256
a = list(map(int,input().split()))
cna = cnb = 0
a.sort()
x = a[2]-a[1]
y = a[1]-a[0]
if a[0]*a[1]*a[2]%2 != 0:
    print(0)
    exit()
while True:
    if x%2 == 0 and x != 0:
        cna += 1
        x //= 2
    else:
        break
while True:
    if y%2 == 0 and y != 0:
        cnb += 1
        y //= 2
    else:
        break
if cna == 0 and cnb == 0:
    print(-1)
else:
    print(min(cna,cnb))

Measured memory_bytes: 61904
/*
  Contest 095
  B - Bitter Alchemy
  Rakesh Kumar --> 23/09/2020
 */

#include <bits/stdc++.h>

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

    int n = 0, x = 0;
    std::cin >> n >> x;
    int m = 0;
    std::cin >> m;
    int min = m;
    int total = m;
    for (int i = 1; i < n; ++i) {
        std::cin >> m;
        total += m;
        min = std::min(m, min);
    }
    std::cout << n + ((x - total) / min) << std::endl;

    return 0;
}


Measured memory_bytes: 3656
while 1:
	n = input()
	if n == 0: break
	taro = sorted([input() for i in range(n)])
	hana = [i for i in range(1,2*n+1) if i not in taro]
	field = 0
	while hana:
		for i in range(len(taro)):
			if taro[i] > field:
				field = taro.pop(i)
				break
		else:
			field = 0
		if len(taro) == 0: break
		for i in range(len(hana)):
			if hana[i] > field:
				field = hana.pop(i)
				break
		else:
			field = 0
	print len(hana)
	print len(taro)

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

int main() {
	string a, b;
	cin >> a >> b;
	string ans = "NO";
	if (a[0] == b[2] && a[1] == b[1] && a[2] == b[0]) ans = "YES";
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int s=0,n=0,m=0;
	cin>>n;
	m=n;
	while(m>0)
	{
		s+=m%10;
		m/=10;
	}
	if(n%s==0)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register 
#define ll long long
#define in inline
using namespace std;
inline ll read(){
	int t=0;
	char v=getchar();
	while(v<'0'||v>'9')v=getchar();
	while(v>='0'&&v<='9'){
		t=(t<<3)+(t<<1)+v-'0';
		v=getchar();
	}
	return t;
}
char s[100002];
ll n,m;
int main(){
	
	cin>>n;
	cin>>s;
	for(re ll i=1;i<strlen(s);++i){
		if(s[i]!=s[i-1])m++;
	}
	printf("%lld",m+1);
}


Measured memory_bytes: 384
#include<stdio.h>

int main(){
	char ss[11],st[11],i,j,t;
	while(0<=scanf(" %s ",ss)){
		for(j=0;j<9;j++){
//			printf("%s\n",ss);
			for(i=0;i<10;i++){
				st[i]=ss[i]-'0'+ss[i+1]-'0';
			}
			
			for(i=0;i<10;i++){
				t=st[i]%10;
				ss[i]=t+'0';
			}
			ss[10-j]='\0';
		}
		printf("%c\n",ss[0]);
	}
	return 0;
}

Measured memory_bytes: 0
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i += 2){
        int cnt = 0;
        for(int j = 1; j <= n; j++){
            cnt += i % j == 0;
        }
        ans += cnt == 8;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {


//	final int MOD = 1000000007;

//	public static long min = 2000000000;
	public static long ans = 0;

	public static void main(String[] args) {

//		int ans = 0;
		Scanner sc = new Scanner(System.in);
		boolean f = false;

//		long k = sc.nextLong();

//		int n = sc.nextInt();
		String string = sc.next();
		String[] s = string.split("");

		//-------------------------------------------------------------------------------------

		if(string.contains("A") && string.contains("B")) {
			f = true;
		}

		//-------------------------------------------------------------------------------------

		if(f) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

//		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 35768
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main(){
    int n;
    cin >> n;
    map<ll, ll> mp; 
    rep(i, n) {
        ll a;
        cin >> a;
        ++mp[a];
    }
    ll max1 = 0;
    ll max2 = 0;
    for ( auto tmp_mp : mp ) {
        if ( max1 < tmp_mp.first && tmp_mp.second >= 4 ) {
            max2 = tmp_mp.first;
            max1 = tmp_mp.first;
        }
        else if ( max1 < tmp_mp.first && tmp_mp.second >= 2 ) {
            max2 = max1;
            max1 = tmp_mp.first;
        }
    }
    cout << max2 * max1 << endl;
    return 0;
}

Measured memory_bytes: 6528
// B - Shift only
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	int minc = INT_MAX;
	for(int i=0; i<N; ++i){
		int a, c = 0;
		for(cin>>a; !(a&1) && a; a>>=1) c++;
		minc = min(minc, c);
	}
	cout<< minc <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

set<int> st;
int main(){
    int n,ai;
    cin>>n;
    rep(i,n){
        cin>>ai;
        st.insert(ai);
    }
    int m;
    cin>>m;
    int ans=0;
    rep(i,m){
        cin>>ai;
        if(st.count(ai)>0) ++ans;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 7780
#include<iostream>
using namespace std;
int main(void){
    int S,h,m,s;
    cin >> S;
    
    s = S % 60;
    S /= 60;
    m = S % 60;
    h = S / 60;
    
      cout << h << ":" << m << ":" << s << endl;
    
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define debug(a) cout<<a<<endl
#define clr(a) memset(a,0,sizeof(a))
#define clrne(a) memset(a,-1,sizeof(a))
#define clrinf(a) memset(a,0x3f,sizeof(a))
#define clrneinf(a) memset(a,0xc0,sizeof(a))
#define pb(a) push_back(a)
#define maxn 10001
#define mod 1000000007
#define eps 1e-9
#define inf 0x7fffffff
int n,y;
int main()
{
//  freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
    cin>>n>>y;
    if (y%1000!=0)
    {
        cout<<"-1 -1 -1"<<endl;
        return 0;
    }
    y/=1000;
    int z = y-n;
    if (z<0)
    {
        cout<<"-1 -1 -1"<<endl;
        return 0;
    }
    for (int i = 0;i*9<=z;i++)
    {
        int yy = z-9*i;
        if (yy%4==0&&yy>=0)
        {
            yy/=4;
            if (n-i-yy<0) continue;
            cout<<i<<' '<<yy<<' '<<n-i-yy<<endl;
//            cout<<i*10000+yy*5000+(n-i-yy)*1000<<endl;
            return 0;
        }
    }
    cout<<"-1 -1 -1"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fst first
#define snd second
#define pb push_back
using namespace std;
const int N=310;
const ll P=1e9+7;
vector<pii>q[N];
ll dp[N][N][N];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	while(m--){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		q[y].pb(mp(x,z));
	}
	dp[1][0][0]=3;//注意dp[1][0][0]有3种取色方案
	for(int i=1;i<=n;++i){
		for(int j=0;j<q[i].size();++j){
			int x=q[i][j].fst,z=q[i][j].snd;
			for(int k=0;k<i;++k)
				for(int p=0;p<=max(0,k-1);++p){
					if(z==1&&k>=x)dp[i][k][p]=-1;
					if(z==2&&(k<x||p>=x))dp[i][k][p]=-1;
					if(z==3&&p<x)dp[i][k][p]=-1;
			}
		}
		if(i==n)break;
		for(int j=0;j<i;++j)
			for(int k=0;k<=max(0,j-1);++k){
				if(dp[i][j][k]==-1)continue;
				(dp[i+1][j][k]+=dp[i][j][k])%=P;
			(dp[i+1][i][k]+=dp[i][j][k])%=P;
				(dp[i+1][i][j]+=dp[i][j][k])%=P;
		}
	}
	ll ans=0;
	for(int j=0;j<n;++j)
		for(int k=0;k<=max(0,j-1);++k)
			if(dp[n][j][k]!=-1)
				(ans+=dp[n][j][k])%=P;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 225536
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s; cin >> s;
  int ans = 700;
  if(s[0] == 'o') ans += 100;
  if(s[1] == 'o') ans += 100;
  if(s[2] == 'o') ans += 100;
  cout << ans << endl;
}

Measured memory_bytes: 256
//




#include <bits/stdc++.h>
using namespace std;


#define spdio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pp pop_back()
#define pf push_front
#define ppf pop_front()
#define ff first
#define ss second
#define mp make_pair
#define fr(i,j,n) for(ll i=j; i<n; i++)
#define rfr(i,j,n) for(ll i=n-1; i>=j; i--)
#define pll pair<ll,ll>
#define plb pair<ll,bool>
#define psl pair<string,ll>
#define psb pair<string,bool>
#define srt(v) sort((v).begin(),(v).end())
#define ub(v,val) upper_bound((v).begin(),(v).end(),(val))-(v).begin()
#define lb(v,val) lower_bound((v).begin(),(v).end(),(val))-(v).begin()


typedef long double ld;
typedef long long int ll;


//getline(cin,string);
const ll inf = (ll) 1e18 + 19;
const ll mod = (ll) 1e9  +  7;




ll ncr(ll n,ll r) {
    ll val=1,i,j,p=2;
    rfr(i,n-r+1,n+1) {
        val*=i;
        while(val%p==0 && p<=r) {
            val/=p;
            p+=1;
        }
    }
    if(p<r) {
        fr(i,p,r+1) val/=i;
    }
    return val;
}




void cazz() {
    ll t=1,i=0,j,n;
    //cin>>t;
    while(t--) {
        ll m,q;
        cin>>n>>m>>q;
        ll a,b,mxr=0,mxc=0,cntr=0,cntc=0;
        map <ll,vector <ll> > mpp1,mpp2;
        map <pll,bool> mpp3;
        ll yup;
        while(q--) {
            cin>>a>>b;
            mpp1[a].pb(b);
            mpp2[b].pb(a);
            mpp3[{a,b}]=true;
            if(mxr==mpp1[a].size()) cntr+=1;
            if(mxc==mpp2[b].size()) cntc+=1;
            if(mxr<mpp1[a].size()) {
                mxr=mpp1[a].size();
                cntr=1;
            }
            if(mxc<mpp2[b].size()) {
                mxc=mpp2[b].size();
                cntc=1;
            }
        }
        ll ans=mxr+mxc;
        ll cnt=cntc;
        for(auto it: mpp1) {
            if(it.ss.size()==mxr) {
                cnt=cntc;
                for(i=0; i<it.ss.size(); i++) {
                    b=mpp1[it.ff][i];
                    if(mpp2[b].size()==mxc) cnt-=1;
                    if(cnt<0) break;
                }
                if(cnt>0) break;
            }
        }
        if(cnt<=0) ans-=1;
        cout<<ans<<"\n";
    }
}




int main() {
    spdio;
	cazz();
	return 0;
}


Measured memory_bytes: 87972
# デバッグ用
GBN_DEBUG = False
GBN_DEBUG = True
def dprn(s, i):
    if GBN_DEBUG: print(", " + s + " = " + str(i), end = "")
def dprns(s):
    if GBN_DEBUG: print(", " + s, end = "")
def dprni(i):
    if GBN_DEBUG: print(i, end=" ")
def endl(): 
    if GBN_DEBUG: print('')
def puts(s): print(s)

#本体ここから

S = input()
#N = int(input())
#S, T = input().split()
#N, M = map(int, input().split())
#W = [input() for _ in range(N)]
#A = list(map(int, input().split()))

zero = S.count('0')
one = S.count('1')

ans = min(zero, one) * 2
print(ans)


Measured memory_bytes: 3188
def main():
    x,y=map(int,input().split())
    ans=0
    if x==1:
        ans+=300000
    if x==2:
        ans+=200000
    if x==3:
        ans+=100000
    if y==1:
        ans+=300000
    if y==2:
        ans+=200000
    if y==3:
        ans+=100000
    if x==1 and y == 1:
        ans+=400000

    print(ans)
if __name__=='__main__':
    main()


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

int n;

vector<int> make_R(int s,int a,int c) {
    vector<int> R(n+1);
    R[0] = s;
    for(int i=1; i<=n; ++i) R[i] = (a*R[i-1]+c)%256;
    return R;
}

vector<int> make_O(vector<int> &I,vector<int> &R) {
    vector<int> O(n);
    for(int i=0; i<n; ++i) O[i] = (I[i]+R[i+1])%256;
    return O;
}

double entropy(vector<int> &o) {
    int cnt[256];
    memset(cnt, 0, sizeof(cnt));

    for(int i=0; i<n; ++i) cnt[o[i]]++;
    double ret = 0;

    for(int i=0; i<256; ++i) {
        double t = (double)cnt[i]/(double)n;
        if(cnt[i] > 0) ret += -t*log(t);
    }
    return ret;
}

int main() {
    while(cin>>n, n) {
        vector<int> I(n);
        for(int i=0; i<n; ++i) cin>>I[i];

        double mH = 1e300,td;
        int aa=0,as=0,ac=0;

        for(int s=0; s<=15; ++s) {
            for(int a=0; a<=15; ++a) {
                for(int c=0; c<=15; ++c) {
                    vector<int> R = make_R(s,a,c);
                    vector<int> O = make_O(I,R);
                    td = entropy(O);

                    if(td + 1e-10 < mH) {
                        mH = td;
                        aa = a,as = s,ac = c;
                    }
                }
            }
        }

        cout<<as<<" "<<aa<<" "<<ac<<endl;
    }
}

Measured memory_bytes: 928
using System;
using System.Collections.Generic;
 
class AOJ_Stack {
    static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        Stack<int> St = new Stack<int>();
        int a, b;

        for (int i = 0; i < s.Length; i++) {
            if (s[i] == "+") {
                b = St.Pop();
                a = St.Pop();
                St.Push(a+b);
            }
            else if (s[i] == "-") {
                b = St.Pop();
                a = St.Pop();
                St.Push(a-b);
            }
            else if (s[i] == "*") {
                b = St.Pop();
                a = St.Pop();
                St.Push(a*b);
            }
            else
                St.Push(int.Parse(s[i]));
        }
        Console.WriteLine(St.Pop());
    }
}

Measured memory_bytes: 10000
import Control.Monad
import Control.Applicative
import Data.List

main :: IO()
main = do
  d <- readLn :: IO Int
  let ans = case d of
            22 -> "Christmas Eve Eve Eve"
            23 -> "Christmas Eve Eve"
            24 -> "Christmas Eve"
            25 -> "Christmas"
            _ ->  "1"
  putStrLn ans


Measured memory_bytes: 508
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

using namespace std;
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int mas=0;
    for(int i=1;i<s.size()-1;i++){
        set<char> s1;
        int k=0;
        for(int j=0;j<i;j++){
           s1.insert(s[j]);
        }
        set<char> s2;


        for(int j=i;j<s.size();j++){
            if(s2.find(s[j])==s2.end()&&s1.find(s[j])!=s1.end()){
                k++;
                s2.insert(s[j]);
            }
        }
        mas=max(mas,k);

    }
cout<<mas<<endl;








}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }






int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;cin >> n >> k;
	ll ans = 0;
	for(ll i = k + 1; i <= n; i++){
		ans += (i - k) * (n / i) + max(n % i - (k - 1), 0LL);
	}
	if(k == 0) ans -= n - k;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

int main()
{
    double A,B,H,M;
    cin >> A >> B >> H >> M;
    double angle;
    H = (H+(M/60.0))*30;
    M = M*6.0;
    angle = abs(H-M);
    if(angle>180) angle = (360.0-angle);
    //cout << angle << endl;
    angle = M_PI*angle/180.0;
    //cout << angle << endl;
    double c;
    c = A*A + B*B - (2.0*A*B*cos(angle));
    c = pow(c,0.5);
    cout << setprecision(11) << c;
   return 0;
}

Measured memory_bytes: 4272
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    int N, K;
    cin >> N >> K;
    vector<ll> A(N), sum(N + 1), B, can;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        sum[i + 1] = A[i];
    }

    rep(i, N) { sum[i + 1] += sum[i]; }

    for (int i = 0; i < N + 1; i++) {
        for (int j = i + 1; j < N + 1; j++) {
            B.push_back(sum[j] - sum[i]);
        }
    }

    sort(all(B));
    vector<ll> now = B;
    for (int i = 63; i > -1; i--) {
        vector<ll> next;
        for (auto n : now) {
            if (n & (1LL << i))
                next.push_back(n);
        }
        // 桁が大きいところにbitフラグが立っている順に、振るい落として候補を絞っていく。
        if (next.size() >= K)
            now = next;
    }

    ll ans = now[0];
    rep(i, K) { ans &= now[i]; }

    cout << ans << endl;
}

Measured memory_bytes: 12952
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;

constexpr int INF = (1<<30)-1;
int main() {
    int N, M; cin >> N >> M;
    vector<string> D(M);
    for (int i = 0; i < M; i++) {
        string T = " ";
        string R; cin >> R;
        D[i] = T + R;
    }

    vint suml(N+1, 0);
    vint sumr(N+2, 0);

    for (int j = 1; j <= N; j++) {
        suml[j] = suml[j-1];
        for (int i = 0; i < M; i++) {
            if (D[i][j] == 'E') suml[j]++;
        }
    }
    for (int j = N; j > 0; j--) {
        sumr[j] = sumr[j+1];
        for (int i = 0; i < M; i++) {
            if (D[i][j] == 'W') sumr[j]++;
        }
    }
    
    int ans = -1, erl = -1, err = -1;
    int minv = INF;
    for (int i = 0; i <= N; i++) {
        int val = suml[i]+sumr[i+1];
        if (minv > val) {
            minv = suml[i]+sumr[i+1];
            erl = suml[i], err = sumr[i+1];
            ans = i;
        } else if (minv == val && erl > suml[i]) {
            erl = suml[i], err = sumr[i];
            ans = i;
        }
    }
    cout << ans << " " << ans + 1 << endl;
    return (0);
}



Measured memory_bytes: 4268
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int const TREE_SIZE = (1 << 20);
long long int seg_tree[TREE_SIZE];

void change(int a, long long int w){
	
	// a番目の要素をwに変更する O(log N)
	
	a += TREE_SIZE / 2;
	
	seg_tree[a] = w;
	
	for(int x = a / 2; x > 0; x /= 2){
		seg_tree[x] = max(seg_tree[2 * x], seg_tree[2 * x + 1]);
	}
}

long long int query(int a, int b, int index, int l, int r){
	
	// 区間 [a, b) の要素の最大値を返す O(log N)
	// 外からは query(a, b, 1, 0, TREE_SIZE / 2) のように呼ぶ
	
	if(r <= a || b <= l){
		return 0;
	}
	if(a <= l && r <= b){
		return seg_tree[index];
	}
	
	return max(query(a, b, index * 2, l, (l + r) / 2), query(a, b, index * 2 + 1, (l + r) / 2, r));
}

long long int a[210000];

int main(){
	
	int N;
	cin >> N;
	
	vector<P> v;
	
	for(int i = 0; i < N; i++){
		int h;
		cin >> h;
		v.push_back(P(h, i + 1));
	}
	
	for(int i = 1; i <= N; i++){
		cin >> a[i];
	}
	
	sort(v.begin(), v.end());
	
	for(int i = 0; i < N; i++){
		int id = v[i].second;
		
		long long int S = a[id] + query(1, id, 1, 0, TREE_SIZE / 2);
		change(id, S);
	}
	
	cout << query(1, N + 1, 1, 0, TREE_SIZE / 2) << endl;
	
	return 0;
}


Measured memory_bytes: 12396
//
#include"bits/stdc++.h"
 

// NOTE TO SELF // try to simplyfy the problem

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

#define ll long long int

//const int mod=1000000007;

using namespace std;


//const ll INF= 1e18L+5 ;

char a[1005][1005];
ll dp[1011][1011];

const int mod= 1e7+7;

int main()
{
 
    ll n,m;
    cin>>n>>m;
    
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            cin>>a[i][j];
        }
        
    }
    
    dp[1][1]=1;
    
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {

            if((i==1 && j==1) || a[i][j]=='#'){
                continue;
            }
            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007LL;
        }
        
    }

    cout<<dp[n][m];
    
}


Measured memory_bytes: 12428
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

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

  int a,b;
  while(cin >> a >> b){
    cout << max({a+b,a-b,a*b}) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b){
    if(a < b) swap(a, b);
    if(b == 0) return a;
    return gcd(b, a % b);
}
int main(){
  int n,ans;
  ans=0;
  cin>>n;
  vector<int> a(n);
  vector<int> l(n+1);
  vector<int> r(n+1);
  l[0]=0;
  r[0]=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
      l[i+1]=gcd(l[i],a[i]);
      r[i+1]=gcd(r[i],a[n-i-1]);
  }
  for(int i=0;i<n;i++){
      ans=max(gcd(l[i],r[n-i-1]),ans);
  }
  cout<<ans;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
 
using namespace std;
typedef long long ll;

ll ans,mx;
int main(){
	ll a,b,k;
	cin>>a>>b>>k;
	if(k>a){
		cout<<0<<" ";
		ans = max(ans,b-(k-a));
		cout<<ans<<endl;
	}
	else cout<<a-k<<" "<<b<<endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<char>> data(H, vector<char>(W));
  vector<bool> Hi(H, false);
  vector<bool> Wi(W, false);

  
  for(int i = 0; i < H; i++){
  	for(int j = 0; j < W; j++){
    	cin >> data[i][j];
    }
  }
  
  for(int i = 0; i < H; i++){
  	for(int j = 0; j < W; j++){
    	if(data[i][j] == '#'){
        	Hi[i] = true;
          	Wi[j] = true;
        }
    }
  }
  for(int i = 0; i < H; i++){
    if(Hi[i]){
   	  for(int j = 0; j < W; j++){
    	if(Wi[j]){
        	cout << data[i][j];
        }
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

//geometric library
//#include <complex>
typedef std::complex<double> Com;

//内積
double dot_product(const Com a, const Com b){
	return (conj(a)*b).real();
}
//外積
double cross_product(const Com a, const Com b){
	return (conj(a)*b).imag();
}
//点と直線の距離
double dist_dot_line(const Com st, const Com en, const Com dt){
    return std::abs(cross_product(dt-st, en-st) / std::abs(en-st));
}
//点と線分の距離
double dist_dot_seg(const Com st, const Com en, const Com dt){
	if(dot_product(en-st, dt-st) <= 0){
		return std::abs(dt-st);
	}else if(dot_product(st-en, dt-en) <= 0){
		return std::abs(dt-en);
	}else{
		return dist_dot_line(st, en, dt);
	}
}
//線分の交差判定
bool seg_crossing(const Com st1, const Com en1, const Com st2, const Com en2){
	double cross1 = cross_product(en1-st1, st2-st1) * cross_product(en1-st1, en2-st1);
	double cross2 = cross_product(en2-st2, st1-st2) * cross_product(en2-st2, en1-st2);
	return (cross1 <= 0) && (cross2 <= 0);
}
//線分と線分の距離
double dist_seg(const Com st1, const Com en1, const Com st2, const Com en2){
	if(seg_crossing(st1, en1, st2, en2)){
		return 0;
	}
	return std::min(std::min(dist_dot_seg(st1, en1, st2), dist_dot_seg(st1, en1, en2)), std::min(dist_dot_seg(st2, en2, st1), dist_dot_seg(st2, en2, en1)));
}

//線分と線分の垂直判定
bool is_vertical(const Com st1, const Com en1, const Com st2, const Com en2){
    if(dot_product(en1-st1, en2-st2) == 0){
        return true;
    }else{
        return false;
    }
}

//平行判定
bool is_parallel(const Com st1, const Com en1, const Com st2, const Com en2){
    if(cross_product(en1-st1, en2-st2) == 0){
        return true;
    }else{
        return false;
    }
}

//直線・線分の交点
Com cross_point(const Com st1, const Com en1, const Com st2, const Com en2){
    /* 線分の時はコメントを外した方が良さそう
    if(dist_seg(st1, en1, st2, en2) > 0 || is_parallel(st1, en1, st2, en2)){
        printf("Error! cross_point invalid input\n");
        std::exit(EXIT_FAILURE);
    }
    //*/
    double den = (real(st1)-real(en1)) * (imag(en2)-imag(st2)) - (real(en2)-real(st2)) * (imag(st1)-imag(en1));
    double mol = (real(en2)-real(en1)) * (imag(en2)-imag(st2)) - (real(en2)-real(st2)) * (imag(en2)-imag(en1));
    double s = mol/den;
    return st1 * s + en1 * (1-s);
}

void solve(){
    double x[4], y[4];
    Com p[4];
    for(int i = 0; i < 4; i++){
        scanf("%lf%lf", &x[i], &y[i]);
        p[i] = Com(x[i], y[i]);
    }
    if(is_parallel(p[0], p[1], p[2], p[3])){
        printf("2\n");
    }else if(is_vertical(p[0], p[1], p[2], p[3])){
        printf("1\n");
    }else{
        printf("0\n");
    }
}

long q;
int main(){
    scanf("%ld", &q);
    for(int i = 0; i < q; i++){
        solve();
    }
}



Measured memory_bytes: 3236
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	int n;
	double h;
	vi data(6);

	cin >> n;
	REP(i, n) {
		cin >> h;
		if(h < 165.0) {
			data[0]++;
		} else if(h < 170.0) {
			data[1]++;
		} else if(h < 175.0) {
			data[2]++;
		} else if(h < 180.0) {
			data[3]++;
		} else if(h < 185.0) {
			data[4]++;
		} else {
			data[5]++;
		}
	}

	REP(i, 6) {
		cout << i+1 << ':';
		REP(j, data[i]) {
			cout << '*';
		}
		cout << endl;
	}

	return 0;
}

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

#define ll long long
#define forn(i, n) for(int i=0; i<int(n); i++)
#define endl '\n'

void lcs(string& s, string& t) {
    int n=s.size(), m=t.size();
    int dp[n+1][m+1];

    forn(i, n+1) dp[i][0] = 0;
    forn(j, m+1) dp[0][j] = 0;

    for(int i=1; i<=n; i++) {
        for(int j=1; j<=m; j++) {
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if(s[i-1] == t[j-1])
                dp[i][j] = max(dp[i][j], 1+dp[i-1][j-1]);
        }
    }



    string res = "";
    int i=n, j=m, l=dp[n][m];

    while(i>0 && l>0){
            if(dp[i-1][j] == dp[i][j])
                i--;
            else if(j>0 && dp[i][j-1] == dp[i][j])
                j--;
            else {
                res = s[i-1] + res;
                i--;
                j--;
                l--;
            }
    }

    cout<<res;
}

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

    string s, t;
    cin>>s>>t;

    lcs(s, t);
}



Measured memory_bytes: 38780
from collections import deque
h, w = map(int, input().split())
c = []
for _ in range(h):
    c.append(input())

ans = 0
for i in range(h):
    for j in range(w):
        if c[i][j] == ".": ans+=1

d = [[-1]*w for _ in range(h)]
d[0][0] = 1
que = deque([[0, 0]])
while que:
    x, y = que.popleft()
    for i, j in [[1,0],[0,1],[-1,0],[0,-1]]:
        nx, ny = x+i, y+j
        if 0<=nx<w and 0<=ny<h and c[ny][nx]=="." and d[ny][nx]==-1:
            d[ny][nx] = d[y][x]+1
            que.append([nx, ny])
if d[h-1][w-1] == -1:
    print(-1)
else:
    print(ans-d[h-1][w-1])

Measured memory_bytes: 3316
## for use in beginner level questions where speed is key
## and also for single test case code
## mastercopy for x,y,z

import sys
import heapq, functools, collections
import random
from collections import Counter, defaultdict

# read line as a string
strr = input()

# read line as an integer
# k = int(input())

# read one line and parse each word as a string
# lst = input().split()

# read one line and parse each word as an integer
# arr = list(map(int,input().split()))

summ = sum([int(x) for x in strr])

if summ%9 == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 11660
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n,k; cin >> n >> k;
    vi p(n);
    rep(i, n) cin >> p[i];
    sort(all(p));
    ll sum = 0;
    rep(i, k) sum += p[i];
    cout << sum << endl;
}

Measured memory_bytes: 3620