akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>

using namespace std;

static const int MAX = 10000;
static const int INFTY = (1<<29);

vector <int> G[MAX];
list<int> out;
bool V[MAX];
int N;
int indeg[MAX];

void bfs(int s){
    queue<int> q;
    q.push(s);
    V[s] = true;
    while (! q.empty()){
        int u = q.front(); q.pop();
        out.push_back(u);
        for (int i=0;i<G[u].size();i++){
            int v = G[u][i];
            indeg[v]--;
            if(indeg[v] == 0 and !V[v]){
                V[v] = true;
                q.push(v);
            }
        }
    }
}

void tsort(){
    for (int i=0;i<N;i++){
        indeg[i] = 0;
    }
    for (int u=0;u<N;u++){
        for (int i=0;i<G[u].size();i++){
            int v = G[u][i];
            indeg[v]++;
        }
    }
    for (int u=0;u<N;u++){
        if (indeg[u] == 0 and !V[u]){
            bfs(u);
        }
    }
    for (list<int>::iterator it= out.begin();it != out.end();it++){
        cout << *it << endl;
    }

}

int main() {
   

    int s,t,M;
    cin >> N >> M;
    for (int i=0;i<N;i++) V[i] = false;

    for (int i=0;i<M;i++){
        cin >> s >> t;
        G[s].push_back(t);
    }
    tsort();

}


Measured memory_bytes: 4072
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  int N;
  cin >> N;
  int c1=0, c2=0, c3=0;
  int ans = 0;
  for(int i=0; i<N; i++){
    string s;
    cin >> s;
    int m = s.length();
    for(int i=0; i<m-1; i++){
      if(s.substr(i, 2) == "AB") ans++;
    }
    if(s[0] == 'B' && s[m-1] == 'A') c1++;
    else if (s[0] == 'B') c2++;
    else if (s[m-1] == 'A') c3++;
  }

  if(c1 == 0){
    ans += min(c2, c3);
  } else {
    ans += c1-1;
    if(c2 > 0 || c3 > 0){
      ans++;
      ans += min(c2, c3);
    }
  }
  cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define mp make_pair
signed main(){
    string s; cin>>s;
    map<char,char>Mp;
    Mp['d']='b';
    Mp['b']='d';
    Mp['p']='q';
    Mp['q']='p';
    string hoge;
    string temp;
    temp=s;
    reverse(all(temp));
    rep(i,temp.size()){
        hoge.push_back(Mp[temp[i]]);
    }
    cout<<(hoge==s?"Yes":"No")<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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 vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

const ll INF = 1e9;
int main() {
  int H, W; cin >> H >> W;
  vector<vector<int>> c(10, vector<int>(10));
  REP(i, 10) {
    REP(k, 10) {
      cin >> c[i][k];
    }
  }
  vector<vector<int>> A(H, vector<int>(W));
  REP(i, H) {
    REP(k, W) {
      cin >> A[i][k];
    }
  }
  for (int k = 0; k < 10; k++){       // 経由する頂点
    for (int i = 0; i < 10; i++) {    // 始点
      for (int j = 0; j < 10; j++) {  // 終点
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }
  ll ans = 0;
  REP(i, H) {
    REP(k, W) {
      if(A[i][k] != 1 && A[i][k] != -1) {
        ans += c[A[i][k]][1];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;

int main() {
  int N, M;
  cin >> N;
  vector<string> s(N);
  rep(i, N) cin >> s[i];
  cin >> M;
  vector<string> t(M);
  rep(i, M) cin >> t[i];
  int res = 0;
  rep(i, N) {
    int sum = 0;
    rep(j, N) if(s[i] == s[j]) sum++;
    rep(j, M) if(s[i] == t[j]) sum--;
    res = max(res, sum);
  }
  cout << res << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        var (n, x) = ReadTuple<int,long>();
        var a = RLongs();
        Array.Sort(a);
        int cnt = 0;
        long sum = 0;
        bool f = true;
        for (int i = 0; i < n; i++)
        {
            if (sum + a[i] <= x)
            {
                cnt++;
                sum += a[i];
            }
            else
            {
                f = false;
                break;
            }
        }
        if (f && sum < x) cnt--;
        WriteLine(cnt);
    }
}



class Scanner
{
    public static string RString() => Console.ReadLine();
    public static int RInt() => ReadTuple<int>();
    public static long RLong() => ReadTuple<long>();
    public static double RDouble() => ReadTuple<double>();

    public static string[] RStrings() => Console.ReadLine().Split();
    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();

    public static T1 ReadTuple<T1>()
    {
        var r = RString();
        var r1 = (T1)Convert.ChangeType(r, typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadTuple<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadTuple<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}


Measured memory_bytes: 27492
#include<stdio.h>
#include<algorithm>
using namespace std;
long long mod=1000000007;
long long dp[2][2][110000];
int b[310];
long long p(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		b/=2;
		a=a*a%mod;
	}
	return ret;
}
int main(){
	int a;
	scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",b+i);
	int c;scanf("%d",&c);
	dp[0][0][0]=1;
	for(int i=0;i<a;i++){
		int t=i%2;
		for(int j=0;j<2;j++)for(int k=0;k<110000;k++)dp[!t][j][k]=0;
		for(int j=0;j<2;j++){
			for(int k=0;k<110000;k++){
				if(!dp[t][j][k])continue;
				dp[!t][!j][k+b[i]]=(dp[!t][!j][k+b[i]]+dp[t][j][k])%mod;
				dp[!t][j][k]=(dp[!t][j][k]+dp[t][j][k])%mod;
			}
		}
	}
	long long ret=0;
	for(int i=0;i<c;i++){
		ret=(ret+(mod+dp[a%2][0][i]-dp[a%2][1][i])*p(c-i,a))%mod;
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 4464
import numpy as np

n = int(input())  
p = np.array(input().split(), dtype=np.int64)

ans = 0
for i in np.arange(n-2) + 1:
    if (p[i] > p[i+1] and p[i] < p[i-1]) or (p[i] < p[i+1] and p[i] > p[i-1]):
        ans += 1
        
print(ans)

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

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

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

int main(){
  solveA();
}


Measured memory_bytes: 256
N,M=map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
G={}
for i in range(1,N*M+1):
  G[i]=[]
for i in range(N):
  G[A[i]].append(i+1)
for i in range(M):
  G[B[i]].append(-(i+1))
A=sorted(A)
B=sorted(B)
ans=1
import bisect
mod=10**9+7
for i in range(N*M,0,-1):
  if len(G[i])>2:
    print(0)
    exit()
  elif len(G[i])==2:
    if G[i][0]*G[i][1]>0:
      print(0)
      exit()
  elif len(G[i])==1:
    if G[i][0]>0:
      d=bisect.bisect_left(B,i)
      ans*=M-d
      ans%=mod
    else:
      e=bisect.bisect_left(A,i)
      ans*=N-e
      ans%=mod
  else:
    d=bisect.bisect_left(B,i)
    e=bisect.bisect_left(A,i)
    f=N*M-i
    if f<0:
      exit()
    ans*=(M-d)*(N-e)-f
    ans%=mod
print(ans)

Measured memory_bytes: 145160
#include<stdio.h>
int a[100001];
int com[100001],x[100001],y[100001],b[100001];
int B=200;
int n,q;
void put(int a[100001]);
int min(int a,int b);
void update(int i,int x);
void find(int s,int t);
int main(void){
  put(a);
  int i;
  scanf("%d %d",&n,&q);
  for(i=0;i<q;i++){
    scanf("%d %d %d",&com[i],&x[i],&y[i]);
    if(com[i]==0)
      update(x[i],y[i]);
    else if(com[i]==1)
      find(x[i],y[i]);
  }
  return 0;
}
int min(int a,int b){
  if(a<=b)
    return a;
  else
    return b;
}
void update(int i,int x){
  int j;
  a[i]=x;
  b[i/B]=2147483647;
  for(j=i-i%B;j<min(i-i%B+B,n);j++){
    b[i/B]=min(b[i/B],a[j]);
  }
}
void find(int s,int t){
  int ans=2147483647;
  int j;
  for(j=s;j<=t;){
    if(j%B==0 && j+B<=t-1){
      ans=min(ans,b[j/B]);
      j+=B;
    }else{
      ans=min(ans,a[j]);
      j++;
    }
  }
  printf("%d\n",ans);
}
void put(int a[100001]){
  int i;
  for(i=0;i<100001;i++)
    a[i]=2147483647,b[i]=2147483647;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  map<string,int> m;
  string prev;
  bool ok=true;
  rep(i,n){
    string s; cin>>s;
    if(i) if(prev[prev.size()-1]!=s[0]) ok=false;
    prev=s;
    m[s]++;
    if(m[s]>1) ok=false;
  }
  if(ok) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main() {
  string s, t;
  cin >> s >> t;

  int n = static_cast<int>(s.size()), m = static_cast<int>(t.size());
  vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));

  rep(i, n) {
    rep(j, m) {
      if (s.at(i) != t.at(j)) {
        dp.at(i + 1).at(j + 1) = max(dp.at(i).at(j + 1), dp.at(i + 1).at(j));
      } else {
        dp.at(i + 1).at(j + 1) = dp.at(i).at(j) + 1;
      }
    }
  }

  string ans;

  int i = n;
  int j = m;
  while (i > 0 && j > 0) {
    if (dp.at(i).at(j) == dp.at(i).at(j - 1)) {
      j--;
    } else if (dp.at(i).at(j) == dp.at(i - 1).at(j)) {
      i--;
    } else {
      i--;
      j--;
      ans.push_back(s.at(i));
    }
  }

  reverse(ans.begin(), ans.end());
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 35584
// Daniel Grzegorzewski
// while (clock()<=69*CLOCKS_PER_SEC)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second
#define int long long

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

int h, w;

signed main() {
  init_ios();
  cin >> h >> w;
  if (h == 1 || w == 1) {
    cout<<"1\n";
    return 0;
  }
  int res = ((w+1)/2 + w/2)*(h/2);
  if (h&1)
    res += (w+1)/2;
  cout<<res<<"\n";
}

Measured memory_bytes: 256
#coding:utf-8
import time

N,Q = map(int,input().split())
rank = [0 for i in range(N)]

class Tree:
    def __init__(self,par,key):
        self.par = par
        self.key = key

List = [Tree(i,i) for i in range(N)]

def unit(x,y):
    while List[x].par != x:
        x = List[x].par
    a = rank[x]
            
    while List[y].par != y:
        y = List[y].par
    b = rank[y]
    if a <= b:
        if a == b:
            rank[x] += 1
        List[y].par = x
    else:
        List[x].par = y



def Find(x,y):
    Q = []
    P = []
    while List[x].par != x:
        x = List[x].par
        Q.append(x)
            
    while List[y].par != y:
        y = List[y].par
        P.append(y)
    for xi in Q:
        List[xi].par = x
        rank[xi] = 1
    for yi in P:
        List[yi].par = y
        rank[yi] = 1
    if x == y:
        print(1)
    else:
        print(0)
    
        
for i in range(Q):
    com, x,y = map(int,input().split())

    if com == 0:
        unit(x,y)
            
    else:
        Find(x,y)





Measured memory_bytes: 8164
// "include" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> l(n);
	rep(i,n){
		cin >> l[i];
	}
	sort(all(l),greater<int>());
	int cnt = 0;
	for(int i = 0;i < n-2;++i){
		for(int j = i+1;j < n-1;++j){
			for(int k = j+1;k < n;++k){
				if(l[j] + l[k] > l[i]) ++cnt;
				else break;
			}
		}
	}
	cout << cnt << '\n';
	return 0;
}


Measured memory_bytes: 256
A = gets.split('/').map(&:to_i)

if A[0] > 2019
  puts 'TBD'
  exit
end
if A[0] == 2019 && A[1] > 4
  puts 'TBD'
  exit
end
if A[0] == 2019 && A[1] == 4 && A[2] > 30
  puts 'TBD'
  exit
end

puts 'Heisei'

Measured memory_bytes: 1788
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef vector<ll> vi;
typedef vector<long long> vl;
typedef pair<ll, ll> pi;
typedef vector<pair<ll, ll>> vpi;
 
//const long long INF = 1LL << 55;
 
#define itn ll
#define endl '\n'
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(ll i = 0;i < n;i++)
#define rep(i,n) for(ll i = 0;i < n;i++)
#define rrep(i,n) for(ll i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, ll mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
 
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

ll n;
ll cnt[300030];
ll D[300030];
int main(void){
   ioboost;
   cin >> n;
   rep(i,n){
      ll a;cin >> a;
      cnt[a]++;
   }
   rep(i,300030){
      D[cnt[i]]++;
   }
   
   vector<ll> k_d(300010,0);
   vector<ll> d_c(300010,0);
   
   rep(i,300010){
      k_d[i+1] = k_d[i] + i * D[i];
      d_c[i+1] = d_c[i] + D[i];
   }
   
   vector<ll> F(300012,0);
   
   rep(X,300010){
      if(!X)continue;
      ll bunbo = 0;
      bunbo += k_d[X+1] + X * (d_c[n+1] - d_c[X+1]);
      F[X] = bunbo / X;
   }
   
  // for(int i = 0;i < 100;i++) cout << F[i] << endl;
  F[0] = LONG_MAX;
  int m;
  rep(i,300010){
      if(!F[i]){m = i;break;}
  }
  F.resize(m+1);
  //for(auto i : F)cout << i << endl;
  reverse(all(F));
  for(ll k = 1;k <= n;k++){
      auto idx = lower_bound(all(F),k);
      cout << m - (idx - F.begin()) << endl;
  }
  
}

Measured memory_bytes: 10624
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>

using namespace std;

/* typedef */
typedef long long ll;

/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;

/* global variables */

/* function */

/* main */
int main(){

    int q; cin >> q;
    int op, x;
    string key;
    map<string, int> mp;

    for (int i = 0; i < q; i++) {
        cin >> op >> key;
        switch(op) {
            case 0:
                cin >> x;
                // insert(key, x) :
                // 
                mp[key] = x;
                break;
            case 1:
                cout << mp[key] << '\n';
        }
    }


}



Measured memory_bytes: 27864
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define ins insert
#define sb substr
#define con continue
#define ub upper_bound
#define lb lower_bound
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define pll pair<ll,ll>
#define pld pair<ld,ld>
using namespace std;

ll power(ll x, ll y);
ll mpower(ll x, ll y, ll p);
ll modInv(ll a, ll m);
ll gcdExtended(ll a, ll b, ll *x, ll *y);
bool isPrime(ll n);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,i,j,k,l,h,p,q,r,x,y,z,a,b,c,d,f,n,m,M=1000000007;
    char ch,ch2,ch3;
    string s,s1,s2,s3;
    // freopen ("input.txt", "r", stdin);
    // freopen ("output.txt", "w", stdout);
    t=1;
    // cin>>t;
    while(t--){
        vector<ll> v,w;
        unordered_map<ll,ll> N;
        set<ll> S,SS;
        cin>>x;
        v.pb(400);
        v.pb(600);
        v.pb(800);
        v.pb(1000);
        v.pb(1200);
        v.pb(1400);
        v.pb(1600);
        v.pb(1800);
        c=1;
        for(i=v.size()-1;i>=0;i--){
            if(v[i]<=x){
                cout<<c<<"\n";
                return 0;
            }
            c++;
        }
    }
    return 0;
}

ll modInv(ll a, ll m){
    ll x, y;
    ll g = gcdExtended(a, m, &x, &y);
    ll res = (x%m + m) % m;
    return res;
}

ll gcdExtended(ll a, ll b, ll *x, ll *y){
    if (a == 0){
        *x = 0, *y = 1;
        return b;
    }
    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, &x1, &y1);
    *x = y1 - (b/a) * x1;
    *y = x1;
    return gcd;
}

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

ll power(ll x, ll y){
    ll res = 1;
    while (y > 0){
        if (y & 1) res = res*x;
        y = y>>1;
        x = x*x;
    }
    return res;
}

bool isPrime(ll n){
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    ll p=sqrt(n);
    for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;
    return true;
}


Measured memory_bytes: 3672
import static java.lang.Math.*;
import static java.util.Arrays.*;

import java.util.*;
import java.io.*;

public class Main {

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i=0;i<n;i++) {
			HashSet<String> set = new HashSet<String>();
			StringBuffer s = new StringBuffer(sc.next());
			set.add(s.toString());
			for(int j=1;j<s.length();j++) {
				StringBuffer s1 = new StringBuffer(s.substring(0, j)), s2 = new StringBuffer(s.substring(j));
				
				set.add(s1.append(s2.reverse()).toString()); s1.delete(j, s.length());
				set.add(s1.reverse().append(s2).toString()); s1.delete(j, s.length());
				set.add(s1.append(s2.reverse()).toString()); s1.delete(j, s.length());
				set.add(s2.append(s1).toString()); s2.delete(s.length()-j, s.length());
				set.add(s2.append(s1.reverse()).toString()); s2.delete(s.length()-j, s.length());
				set.add(s2.reverse().append(s1).toString()); s2.delete(s.length()-j, s.length());
				set.add(s2.append(s1.reverse()).toString());
//				debug(set);
			}
//			debug(i, set);
			System.out.println(set.size());
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 38068
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int N, M;
vector<pair<int,int>> E[101010];
string ans[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M;
    rep(i, 0, M) {
        int p, y; cin >> p >> y;
        E[p].push_back({ y, i });
    }
    rep(i, 1, N + 1) {
        sort(all(E[i]));
        int n = E[i].size();
        rep(j, 0, n) {
            char buf[13];
            sprintf(buf, "%06d%06d", i, j + 1);
            ans[E[i][j].second] = string(buf);
        }
    }
    rep(i, 0, M) printf("%s\n", ans[i].c_str());
}

Measured memory_bytes: 12544
#include <bits/stdc++.h>
 
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sll set<long long>
#define si set<int>
#define stk stack<int>
#define que queue<int>
#define pb push_back
#define ff first
#define ss second
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
using namespace std;

void solve(){
	int x,y;
	cin>>x>>y;
	int b=0;

	if(x==1&&(y==2||y==4))
		b=1;

	for(int i=1;i<=x;i++){
		if(i*2+(x-i)*4==y||i*4+(x-i)*2==y){
			b=i;
			break;
		}
	}

	if(b==0)
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;

}
 
int main(){
    IOS;
    int q=1;
    //cin>>q;
    while(q--){
        solve();
    }
}

Measured memory_bytes: 3652
#include<cstdio>
#include<functional>
#include<algorithm>

using namespace std;

int N, data[200], s[200];

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

  int n = N*(N-1)/2;

  int a,b,c,d;
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if (c > d) {
      data[a] += 3;
    } else if (c < d) {
      data[b] += 3;
    } else {
      data[a] += 1;
      data[b] += 1;
    }
  }

  for (int i = 0; i < 200; i++) s[i] = data[i];

  sort(s, s+200, greater<int>());

  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < 200; j++) {
      if (data[i] == s[j]) {
	printf("%d\n",j+1);
	break;
      } 
    }
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define int 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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a-1);i>=(b);i--)
#define all(x) (x).begin(), (x).end()
const int INF = 1e18;
const int MOD = 1e9+7;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef string str;
typedef vector<str> vstr;
void print() {cout<<endl;}template<class Head,class...Tail>void print(Head&&head,Tail&&...tail){cout<<head;if(sizeof...(tail)!=0)cout<<" ";print(forward<Tail>(tail)...);}template<class T>void print(vector<T>&vec){for(auto&a:vec){cout<<a;if(&a!=&vec.back())cout<<" ";}cout<<endl;}template<class T>void print(vector<vector<T>>&df){for(auto&vec:df){print(vec);}}
template<class T=int>T in() {T x;cin>>x;return(x);}
template<class T=int>vector<T> input_to_vector(int n) {vector<T>x;rep(i,n){T a;cin>>a;x.push_back(a);}return(x);}

signed main(){
    int n = in();
    vint P = input_to_vector(n);
    sort(all(P));
    P[n-1] = P[n-1] / 2;
    int ans = accumulate(all(P), 0);
    print(ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#define ll long long
using namespace std;
const int N=100000+7;
int n,a[N],l,r,mid,c[3*N],t[N];
ll s[N];
int lowbit(int x){
	return x&-x;
}
void add(int x){
	for(int i=x;i<=2*N;i+=lowbit(i))
		c[i]++;
}
int query(int x){
	ll sum=0;
	for(int i=x;i>=1;i-=lowbit(i))
		sum+=c[i];
	return sum;
}
bool check(int now){
    for(int i=1;i<=2*N;i++)c[i]=0;		//用memset会出错 
	for(int i=1;i<=n;i++){
		s[i]=s[i-1]+(a[i]>=now ?1 :-1);
		//if(now==9)printf("%d ",s[i]);
	}
	//printf("\n");
	ll sum=0;
	for(int i=0;i<=n;i++){
		sum+=query(s[i]+N);
		add(s[i]+N);
	}
	//printf("%d %d\n",now,sum);
	return sum>=1ll*n*(n+1)/4;
}
int main(){
	//freopen("1.txt","r",stdin);
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		r=max(r,a[i]);
	}
	while(l<=r){			//一定要用 <=，不然会漏情况 
		mid=(l+r)>>1;
		if(check(mid))l=mid+1;
		else r=mid-1;
	}
	printf("%d\n",r);
	return 0;
}
/*
3
10 30 20

*/
/*
10
5 9 5 9 8 9 3 5 4 3

*/

Measured memory_bytes: 2176
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u32 = read();

    let mut target_array: Vec<u32> = (0..n).map(|_| read::<u32>()).collect();
    let mut count = 0;

    for i in 0..n {
        let mut min_j = i;
        for j in i..n {
            if target_array[j as usize] < target_array[min_j as usize] {
                min_j = j
            };
        }
        if min_j != i {
            let temp = target_array[i as usize];
            target_array[i as usize] = target_array[min_j as usize];
            target_array[min_j as usize] = temp;
            count += 1;
        }
    }

    for index in 0..n {
        if index != n - 1 {
            print!("{} ", target_array[index as usize]);
        } else {
            print!("{}", target_array[index as usize]);
        }
    }
    println!("");
    println!("{}", count);
}



Measured memory_bytes: 5024
from itertools import combinations
from collections import Counter


def main():
    n = int(input())
    l = list(map(int, input().split()))
    c = Counter(l)
    s = list(c.keys())

    ans = 0
    for item in combinations(s, 3):
        item = sorted(item)
        if item[2] < item[0] + item[1]:
            ans_this = 1
            for i in item:
                ans_this *= c[i]
            ans += ans_this
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9456
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        System.out.print("Christmas");
        for (int i = a; i < 25; i++) {
            System.out.print(" Eve");
        }
        System.out.println("");
    }
}

Measured memory_bytes: 21716
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	static String[][] dp;
	static char[][] code;
	static int W;
	static int H;
	public static void main(String[] args) {
		solve();
	}

	private static void solve() {
		Scanner sc = new Scanner(System.in);
		PrintWriter pr = new PrintWriter(System.out);
		
		while (true) {
			W = sc.nextInt();
			H = sc.nextInt();
			if(W==0&&H==0) break;
			dp = new String[H][W];
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					dp[i][j] = "-1";
				}
			}
			code = new char[H][W];
			for (int i = 0; i < H; i++) {
				String tmp = sc.next();
				for (int j = 0; j < W; j++) {
					code[i][j] = tmp.charAt(j);
				}
			}
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					dinamic(i, j);
				}
			}
			String maxtmp = "0";
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if(dp[i][j].charAt(0)!='0'){
						maxtmp = max(maxtmp,dp[i][j]);
					}
				}
			}
			pr.println(maxtmp);
		}
		pr.flush();
		sc.close();
	}

	private static String dinamic(int i, int j) {
		if(dp[i][j].equals("-1")==false) return dp[i][j];
		if(code[i][j]<'0'||code[i][j]>'9'){
			return dp[i][j];
		}else{
			String tmp1;
			String tmp2;
			if(i+1==H){
				tmp1 = "-1";
			}else{
				tmp1= dinamic(i+1,j);
			}
			if(j+1==W){
				tmp2 = "-1";
			}else{
				tmp2= dinamic(i,j+1);
			}
			if(tmp1.equals("-1")==false){
				tmp1 = code[i][j]+tmp1;
			}
			if(tmp2.equals("-1")==false){
				tmp2 = code[i][j]+tmp2;
			}
			if(tmp1.equals("-1")&&tmp2.equals("-1")){
				dp[i][j] = String.valueOf(code[i][j]);
				return String.valueOf(code[i][j]);
			}
			dp[i][j] = max(tmp1, tmp2);
			return dp[i][j];
		}
	}

	private static String max(String tmp1, String tmp2) {
		if(tmp1.equals("-1")){
			return tmp2;
		}
		if(tmp2.equals("-1")){
			return tmp1;
		}
		if(tmp1.length()>tmp2.length()){
			return tmp1;
		}else if(tmp1.length()<tmp2.length()){
			return tmp2;
		}else{
			for(int k=0;k<tmp1.length();k++){
				if(tmp1.charAt(k)-'0'>tmp2.charAt(k)-'0'){
					return tmp1;
				}else if(tmp1.charAt(k)-'0'<tmp2.charAt(k)-'0'){
					return tmp2;
				}
			}
		}
		return tmp1;
	}
}

Measured memory_bytes: 72664
// AtCode.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>

using namespace std;


int main()
{
	int N, Y;
	cin >> N >> Y;
	bool found = false;
	int A = 0;
	int B = 0;
	int C = 0;
	for (A = 0; A <= min(N,Y/10000); A++) {
		for (B = 0; B <= min(N,Y/5000); B++) {
			C = (Y - 10000*A - 5000*B)/1000;
			if ( (C >= 0) && (10000 * A + 5000 * B + 1000 * C == Y) && (A+B+C==N)) {
				found = true;
				break;
			}
			if (found) break;
		}
		if (found) break;
	}
	if (found) cout << A << " " << B << " " << C << endl;
	else cout << "-1 -1 -1" << endl;
	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define x first
#define y second
#define pb push_back

using namespace std;
typedef long long ll;
int dp[3][105], a[3][105];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= 2; i++)
        for (int j = 1; j <= n; j++)
            cin >> a[i][j];

    dp[1][1] = a[1][1];
    dp[2][1] = a[1][1] + a[2][1];
    for (int i = 2; i <= n; i++)
    {
        dp[1][i] = dp[1][i - 1] + a[1][i];
        dp[2][i] = max(dp[1][i], dp[2][i - 1]) + a[2][i];
    }
    cout << dp[2][n];
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
num = 0
zan = 0
for i in range(N):
    if A[i] <= B[i]:
        zan = B[i] - A[i]
        num += A[i]
        if zan >= A[i + 1]:
            num += A[i + 1]
            A[i + 1] = 0

        else:
            num += zan
            A[i + 1] -= zan

    else:
        num += B[i]


#num += min(A[N], zan)

print(num)

Measured memory_bytes: 18624
import sys
from operator import itemgetter
read = sys.stdin.read

N, K, *td = map(int, read().split())
td = sorted(zip(*[iter(td)] * 2), key=itemgetter(1), reverse=True)

stack = []
taste = 0
neta_group = set()
for t, d in td[:K]:
    taste += d
    if t in neta_group:
        stack.append(d)
    else:
        neta_group.add(t)

variety = len(neta_group)
candidates = [taste + variety ** 2]

if N == K:
    print(candidates[0])
    exit()

rest = list(reversed(td[K::]))

while rest and stack:
    t1, d1 = rest.pop()
    if t1 not in neta_group:
        neta_group.add(t1)
        d2 = stack.pop()
        variety += 1
        taste = taste - d2 + d1

        candidates.append(taste + variety ** 2)

print(max(candidates))

Measured memory_bytes: 25316
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int ar[6];
    for(int i=1;i<=5;i++)
    cin>>ar[i];
    for(int i=1;i<=5;i++)
    {
        if(ar[i]==0)
        {
            cout<<i;
            return 0;
        }
    }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  int g = __gcd(n, m);
  for (int i = 0; i < g; i++) {
    int x = n / g * i;
    int y = m / g * i;
    if (s[x] != t[y]) {
      cout << -1 << '\n';
      return 0;
    }
  }
  cout << (long long) n / g * m << '\n';
  return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

const auto MOD = static_cast<ll>(1e9 + 7);

ll N = 0, ans = 0;
vector<ll> A;

int main() {
    cin >> N; A.resize(3 * N);
    for (auto& item : A) cin >> item;
    sort(A.begin(), A.end());
    for (int i = 0; i < N; i++) {
        ans += A[A.size() - 2 - 2 * i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
import math

a,b,h,m = [int(i) for i in input().split()]
a_rad = 0.5 * (60*h+m)
b_rad = 6*m

rad_diff = abs(a_rad - b_rad)

x2 = a*a + b*b -2*a*b*math.cos(math.radians(rad_diff))

print(math.sqrt(x2))

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

#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pii     pair<int, int>
#define ll      long long

void solve() {
        string s;
        cin >> s;
        if (s[0] == '9' || s[1] == '9') cout << "Yes" << endl;
        else cout << "No" << endl;
        return;
}

int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        solve();
        return 0;
}


Measured memory_bytes: 256
import numpy as np
import bisect

N,M=map(int,input().split())
A = np.array(list(map(int,input().split())),dtype="int64")

A.sort()
# print(A)
tmpD=[]

for m in range(M):
	tmpD.append(list(map(int,input().split())))

tmpD.sort(key=lambda x:x[1],reverse=True)
D = np.array(tmpD)

curB = 0
dIndex=0
for n in range(N):

	if A[n] < D[dIndex][1]:
		A[n] = D[dIndex][1]
	else:
		break

	curB+=1
	if D[dIndex][0] <= curB:
		curB=0
		dIndex+=1
		if len(D) <= dIndex:
			break

# print(A)


print( A.sum() )


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////


#define MAx 1000000

ll A,B;
vector<ll> Amod,Bmod;
ll pr[1010101];
vector<ll> prs;
ll i, j, k,ans;

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

int main(){
    scanf("%lld%lld", &A, &B);
    ll g = gcd(A, B);
    ll g2 = g;
    ans++;
    fornum(i,2,MAx){
        if(pr[i])
            continue;
        if(g%i==0){
            while(g2%i==0){
                g2 /= i;
            }
            ans++;
        }
        for (j = i; j <= MAx;j+=i){
            pr[j] = 1;
        }
    }
    if(g2>MAx){
        ans++;
    }
    printf("%lld", ans);
    return 0;
}

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

int h, w;
vector<string> s;
vector<vector<bool>> visited;
vector<int> dx = {1,0,-1,0};
vector<int> dy = {0,1,0,-1};

long long int black, white;
void DFS(int x, int y){
    if(visited[x][y] == true) return ;

    visited[x][y] = true;
    if(s[x][y] == '#') black += 1;
    if(s[x][y] == '.') white += 1;

    for(int i=0; i<4; i++){
        if(0 <= x+dx[i] && x+dx[i] < h
        && 0 <= y+dy[i] && y+dy[i] < w
        && s[x][y] != s[x+dx[i]][y+dy[i]]){
            DFS(x+dx[i],y+dy[i]);
        }
    }
}

int main(){
    cin >> h >> w;

    s.resize(h);
    for(int i=0; i<h; i++){
        cin >> s[i];
    }

    long long int ans = 0;
    visited.assign(h, vector<bool>(w,false));
    for(int x=0; x<h; x++){
        for(int y=0; y<w; y++){
            if(visited[x][y] == false){
                black = 0;
                white = 0;
                DFS(x,y);
                ans += black * white;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13836
#include <stdio.h>
#include <stdlib.h>
void maxHeapify(int *,int ,int);
int main() {
  int i,n;
  int *H;
  scanf("%d",&n);
  H = malloc((n+1)*sizeof(int));
  for(i=1;i<=n;i++)
    {
      scanf("%d",&H[i]);
    }
  
   for(i=n/2;i>0;i--)
     {
       maxHeapify(H,i,n);
     }

   for(i=1;i<=n;i++)
    {
      printf(" %d",H[i]); 
    }
   printf("\n");
   
  return 0;
}
void maxHeapify(int *A,int i, int n)
{
  int j,largest;
  int emp;

  if(2*i <= n && A[2*i] > A[i]) largest = 2*i;
  else largest = i;
  if((2*i)+1 <= n && A[2*i+1] > A[largest]) largest = (2*i)+1;
  if(largest != i)
    {
      emp = A[largest];
      A[largest]= A[i];
      A[i] = emp;
      maxHeapify(A,largest,n);
    }

}



Measured memory_bytes: 3640
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        for(int i=0;i<n;i++) {
            double x1 = sc.nextDouble();
            double y1 = sc.nextDouble();
            double x2 = sc.nextDouble();
            double y2 = sc.nextDouble();
            double x3 = sc.nextDouble();
            double y3 = sc.nextDouble();
            double x4 = sc.nextDouble();
            double y4 = sc.nextDouble();
            if(Math.abs((x2-x1)*(y4-y3)-(y2-y1)*(x4-x3))<1e-10){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }
    }
}

Measured memory_bytes: 23224
#include <iostream>
#include <cstring>
#define ll long long
#define INF (ll)1e15
#define MAXN 20005 
#define V 205
using namespace std;
ll r[V], g[V][V];
ll n, m, R, k = 1, ans = INF;
bool vst[V];

void dfs(ll x, ll step, ll cost) {
	if(step == R) {
		ans = min(ans, cost);
		return;
	}
	for(ll i = 1; i <= R; i++) {
		if(!vst[r[i]] && g[x][r[i]] != INF) {
			vst[r[i]] = 1;
			dfs(r[i], step+1, cost+g[x][r[i]]);
			vst[r[i]] = 0;
		}
	}
	
}

int main() { 
	ll x, y, c; 
	cin >> n >> m >> R; 
	for(int i = 1; i <= n; i++) 
		for(int j = 1; j <= n; j++) 
			if(i != j) g[i][j] = INF;
	for(ll i = 1; i <= R; i++) 
		cin >> r[i];
	for(ll i = 1; i <= m; i++) {
		cin >> x >> y >> c;
		if(g[x][y] > c) {
			g[x][y] = c;
			g[y][x] = c;
		}
	}
	for(ll k1 = 1; k1 <= n; k1++) 
		for(ll i = 1; i <= n; i++) 
			for(ll j = 1; j <= n; j++) 
				g[i][j] = min(g[i][j], g[i][k1] + g[k1][j]);
	for(int i = 1; i <= R; i++) {
		memset(vst, 0, sizeof vst);
		vst[r[i]] = 1;
		dfs(r[i], 1, 0);
	}			
	
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int nax=1e5+5;
const int mod=1e9+7;
vector<int> edges[nax];

ll mul(ll a,ll b){
    return(a*b)%mod;
}

pair<ll,ll> dfs(int u,int prev){
    ll all_white=1; //no of ways to paint with black color
    ll sth_is_black=0;
    for(auto v:edges[u]){
        if(v!=prev){
            pair<ll,ll> res=dfs(v,u);
            sth_is_black=(mul(all_white,res.first)+mul(sth_is_black,(res.first+res.second)%mod))%mod;
            all_white=mul(all_white,res.second);
        }
    }
    return {all_white,(all_white+sth_is_black)%mod};
}

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        edges[x].push_back(y);
        edges[y].push_back(x);
    }
   pair<ll,ll> ans= dfs(1,-1);
   ll answer=(ans.first+ans.second)%mod;
   cout<<answer;
}


Measured memory_bytes: 15952
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    long X, Y;
    scan(X, Y);
    if ((2 * Y - X) % 3 != 0 || (2 * X - Y) % 3 != 0)
    {
        writeln(0);
        return;
    }
    long m = (2 * Y - X) / 3;
    long n = (2 * X - Y) / 3;
    if (m < 0 || n < 0)
    {
        writeln(0);
        return;
    }
    combination_mod(m + n, n, MOD).writeln();
}

T combination_mod(T = long)(T n, T k, T m)
{
    long a = 1;
    long b = 1;
    long c = 1;
    foreach (i; 1 .. n + 1)
    {
        a = (a * i) % m;
        if (i == k)
            b = a;
        if (i == (n - k))
            c = a;
    }
    T powmod(T = long)(T x, T n, T m)
    {
        if (n < 1)
            return 1;
        if (n & 1)
        {
            return x * powmod(x, n - 1, m) % m;
        }
        T tmp = powmod(x, n / 2, m);
        return tmp * tmp % m;
    }

    long bc = b * c % m;
    long bc_inv = powmod(bc, m - 2, m);
    return a * bc_inv % m;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MOD 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define fast ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define umll unordered_map<ll,ll>
#define mll map<ll,ll>
#define forr(i,p,n) for(ll i=p;i<(ll)n;i++)
#define fore(i,n,k) for(ll i=n-1;i>=k;i--)
#define MAXN 1000003
typedef long long ll;
using namespace std;
ll mult(ll a, ll b, ll p = MOD) {return ((a % p) * (b % p)) % p;}
ll add(ll a, ll b, ll p = MOD) {return (a % p + b % p) % p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD) {ll m0 = m; ll y = 0, x = 1; if (m == 1)return 0; while (a > 1) {ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t;} if (x < 0)x += m0; return x;}
using namespace __gnu_pbds;
typedef tree<ll, null_type, less< ll>, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
ll dp[101][100001];
void functiontosolve()
{
    ll n, W;
    cin >> n >> W;
    ll w[n + 1], val[n + 1];
    forr(i, 1, n + 1) cin >> w[i] >> val[i];
    forr(i, 1, n + 1) {
        forr(j, 0, W + 1) {
            if (j == 0 or i == 0) dp[i][j] = 0;
            else {
                dp[i][j] = dp[i - 1][j];
                if (w[i] <= j) dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + val[i]);
            }
        }
    }
    cout << dp[n][W] << '\n';
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int test;
    test  = 1;
    forr(i, 1, test + 1) {
        functiontosolve();
    }
    return 0;
}

Measured memory_bytes: 81644