akhauriyash/Code-Regression huggingface dataset:
W, H ,N = map(int, input().split())

C = [[1 for i in range(W)] for j in range(H)]

for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        for i in range(x):
            for j in range(H):
                C[j][i] = 0
    elif a == 2:
        for i in range(x,W):
            for j in range(H):
                C[j][i] = 0
    elif a == 3:
        for i in range(y):
            for j in range(W):
                C[i][j] = 0
    elif a == 4:
        for i in range(y,H):
            for j in range(W):
                C[i][j] = 0


ans = 0

for i in range(H):
    ans += sum(C[i])


print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll N;
  cin >> N;
  vll A(N);
  rep(i, N) cin >> A[i];
  SORT(A);
  REVERSE(A);
  ll ans = 0;
  rep(i, N) {
    if (i == 0) continue;
    ans += A[i / 2];
  }
  ANS;
  return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;


int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int n;
    cin>>n;
    int pat = 0;
    for(int a=1;a<n;++a){
        pat += (n-1)/a;
    }
    cout << pat << endl;
    return 0;
    
}

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

using namespace std;

int main()
{
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    int sum = 0;
    for (int i = 1; i <= N; i++) {
        if (i <= K) sum += X;
        else sum += Y;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

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

    LL evennum = 0;
    for(int i = 0; i < 3; i++){
        if(a[i]%2 == 0){
            evennum++;
        }
    }
    LL ans = 0;
    if(evennum == 1){
        LL ind;
        for(int i = 0; i < 3; i++){
            if(a[i]%2 == 0){
                ind = i;
            }
        }
        for(int i = 0; i < 3; i++){
            if(i != ind){
                a[i]++;
            }
        }
        ans++;
    }else if(evennum == 2){
        LL ind;
        for(int i = 0; i < 3; i++){
            if(a[i]%2 != 0){
                ind = i;
            }
        }
        for(int i = 0; i < 3; i++){
            if(i != ind){
                a[i]++;
            }
        }
        ans++;
    }

    LL m = max(a[0],max(a[1],a[2]));
    for(int i = 0; i < 3; i++){
        ans += (m-a[i])/2;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5])
	{
		cout<<"Yes"<<endl;
	}
	else 
	{
		cout<<"No"<<endl;
	}
	return 0;
}

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

using namespace std;

int main(void) {
    int64_t H, W;
    cin >> H >> W;
    if(H%3 == 0 || W%3 == 0) {
        cout << 0 << endl;
    } else {
        int64_t ans = INT64_MAX;
        for(int64_t i=1; i<H; i++) {
            int64_t S1 = i*W;
            int64_t S2 = (H-i) * (W/2);
            int64_t S3 = H*W - S1 - S2;
            ans = min(ans, max({S1, S2, S3}) - min({S1, S2, S3}));
        }
        for(int64_t j=1; j<W; j++) {
            int64_t S1 = j*H;
            int64_t S2 = (W-j) * (H/2);
            int64_t S3 = H*W - S1 - S2;
            ans = min(ans, max({S1, S2, S3}) - min({S1, S2, S3}));
        }
        ans = min(ans, H);
        ans = min(ans, W);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
    int A1;
    int A2;
    int A3;
    cin >> A1 >> A2 >> A3;
    if (A1+A2+A3>21){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }
}

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	LL N, M, X, Y;
	cin >> N >> M >> X >> Y;

	vector<LL> A, B;
	A.push_back(X);
	for(int i=0; i<N; i++){
		LL a;
		cin >> a;
		A.push_back(a);
	}
	B.push_back(Y);
	for(int i=0; i<M; i++){
		LL b;
		cin >> b;
		B.push_back(b);
	}
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());

	LL u = A[A.size()-1];
	LL v = B[0];
	if(u < v){
		printf("No War\n");
	}
	else{
		printf("War\n");
	}
	return 0;
}



Measured memory_bytes: 3604
h, w = map(int, raw_input().split())
s = [list(raw_input().strip()) for _ in xrange(h)]
def dfs(x, y):
    if x == w - 1 and y == h - 1:
        s[y][x] = '.'
        return 1
    if x < w - 1 and s[y][x+1] == '#' and dfs(x + 1, y):
        s[y][x] = '.'
        return 1
    if y < h - 1 and s[y+1][x] == '#' and dfs(x, y + 1):
        s[y][x] = '.'
        return 1
    return 0
if dfs(0, 0) and sum(''.join(r).count('#') for r in s) == 0:
    print "Possible"
else:
    print "Impossible"


Measured memory_bytes: 2696
#include <iostream>
#include <cmath>

#include <vector>
#include <algorithm>
#include <limits>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <queue>

typedef long long ll;

using namespace std;


int main() {
    int n;
    cin >> n;
    ll a = 1, b = 1, c = 1;
    ll m = pow(10, 9) + 7;
    for (int i = 0; i < n; ++i) {
        a = (10 * a) % m;
        b = (9 * b) % m;
        c = (8 * c) % m;
    }
    ll ans = (((a + c) % m) - ((2 * b) % m)) % m;
    if (ans < 0) {
        ans += m;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3540
import java.util.Scanner;

public class Main {
	static Scanner sc =  new java.util.Scanner(System.in);

	public static void main(String[] args) {
		
		
		while ( sc.hasNext() ){
		
		double w = sc.nextDouble();
		
		if ( w <= 48.00){
			System.out.println( "light fly" );
		}else if( w <= 51.00 && w >= 48.00 ){
			System.out.println( "fly" );
		}else if ( w <= 54.00 && w >= 51.00 ){
			System.out.println( "bantam" );
		}else if ( w <= 57.00 && w >= 54.00 ){
			System.out.println( "feather" );
		}else if ( w <= 60.00 && w >= 57.00 ){
			System.out.println( "light" );
		}else if ( w <= 64.00 && w >=60.00 ){
			System.out.println( "light welter" );
		}else if ( w <= 69.00 && w >= 64.00 ){
			System.out.println( "welter" );
		}else if ( w <= 75.00 && w >= 69.00 ){
			System.out.println( "light middle" );
		}else if ( w <= 81.00 && w >= 75.00 ){
			System.out.println( "middle" );
		}else if ( w <= 91.00 && w >= 81.00 ){
			System.out.println( "light heavy" );
		}else {
			System.out.println( "heavy" );
		}
		
	
		}

	}

}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

int val(int a, int b, int num) {
    if(a%num) {
        a = a - a%num + num;
    }
    if(b%num) {
        b -= b%num;
    }

    int ret = (b-a)/num + 1;
    return ret;
}

int32_t main() {

    int a, b, c, d; cin >> a >> b >> c >> d;

    int ans = b-a+1 - val(a, b, c)- val(a, b, d) + val(a, b, c*d/__gcd(c, d));

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define YES 1
#define NO 0

int tri_judge(int x, int y, int z);
int pow2(int x);

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

    int side1, side2, side3;
    while (dataset--){
        scanf("%d %d %d", &side1, &side2, &side3);
        int yn = tri_judge(side1, side2, side3);
        if (yn == YES){
            printf("YES\n");
        } else {
            printf("NO\n");
        }

    }

    return 0;
}

int tri_judge(int x, int y, int z)
{
    int yn;

    if (pow2(x) == pow2(y) + pow2(z)){
        yn = YES;
    } else if (pow2(y) == pow2(z) + pow2(x)){
        yn = YES;
    } else if (pow2(z) == pow2(x) + pow2(y)){
        yn = YES;
    } else {
        yn = NO;
    }

    return yn;
}

int pow2(int x)
{
    return x * x;
}

Measured memory_bytes: 1008
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        long[] sum = new long[N+1];
        for(int i = 1;i < N+1;i++)    sum[i] = sum[i-1]+sc.nextLong();
        long ans = Long.MAX_VALUE;
        long[] A = new long[4];
        for(int i = 2;i < N-1;i++){
            int min = 1;
            int max = i;
            while(true){
                int mid = (min+max)/2;
                A[0] = sum[mid]-sum[0];
                A[1] = sum[i]-sum[mid];
                if(max-min == 2 && A[0] > A[1]){
                    if(A[0]-A[1] <= (sum[i]-sum[mid-1])-(sum[mid-1]-sum[0])){
                        break;
                    }else{
                        A[0] = sum[mid-1]-sum[0];
                        A[1] = sum[i]-sum[mid-1];
                        break;
                    }
                }
                if(A[0] < A[1])   min = mid;
                else if(A[0] > A[1])    max = mid+1;
                if(A[0] == A[1] || max-min == 1)  break;
            }
            min = i+1;
            max = N;
            while(true){
                int mid = (min+max)/2;
                A[2] = sum[mid]-sum[i];
                A[3] = sum[N]-sum[mid];
                if(max-min == 2 && A[2] > A[3]){
                    if(A[2]-A[3] <= (sum[N]-sum[mid-1])-(sum[mid-1]-sum[i])){
                        break;
                    }else{
                        A[2] = sum[mid-1]-sum[i];
                        A[3] = sum[N]-sum[mid-1];
                        break;
                    }
                }
                if(A[2] < A[3])   min = mid;
                else    max = mid+1;
                if(A[2] == A[3] || max-min == 1)  break;
            }
            Arrays.sort(A);
            ans = Math.min(ans, A[3]-A[0]);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 89692
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    int L = sc.nextInt();
	    
	    if (L>=0){
	    	int ans =0;
	    	for (int i=L+1; i<N+L; i++){
	    		ans+=i;
	    	}
	    	System.out.println(ans);
	    }
	    	
	    else if (N+L>0){
	    	int ans =0;
	    	for (int i=L; i<N+L; i++){
	    		ans+=i;
	    	}
	    	System.out.println(ans);
	    }
	    
	    else {
	    	int ans = 0;
	    	for (int i=L; i<N+L-1; i++){
	    		ans+=i;
	    	}
	    	System.out.println(ans);
	    }
	    
	    
	    
	    
	    System.out.println();

	}

}

Measured memory_bytes: 21844
datas = gets.split.map{|n|n.to_i}
n = datas[0]
a = datas[1]
b = datas[2]
c = datas[3]
d = datas[4]
mapstring = gets
activemap = (mapstring[(a-1)..(c-1)].include?("##") or mapstring[(b-1)..(d-1)].include?("##"))
clearflag = true
if activemap
  clearflag = false
else
  if c < d
    clearflag = true
  else
    submap = mapstring[((b-2)..(d))]
    clearflag = submap.include?("...")
  end
end


if clearflag
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 2300
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
#define rep1(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
const ll mod = 998244353;
const double e = 0.000000001;
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(){
  ll n; cin >>n;
  map<ll,ll> m = prime_factor(n);
  ll ans=0;
  for(auto p:m){
    ll k = p.first;
    ll v = p.second;
    ll cnt=0;
    for(ll j=1; j<=v; j++){
      if(v<j) break;
      v-=j;
      cnt++;
    }
    ans +=cnt;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3628
n=int(input())
a=[int(i) for i in input().split()]
ans=[]
positive_flag=True


if 0<=min(a):
        positive_flag=True
elif max(a)<=0:
        positive_flag=False
elif min(a)*(-1) <= max(a):
        positive_flag=True
        maxId=a.index(max(a))
        for i in range(n):
                if i!=maxId:
                        ans.append([maxId+1,i+1])
else:
        positive_flag=False
        minId=a.index(min(a))
        for i in range(n):
                if i!=minId:
                        ans.append([minId+1,i+1])

if positive_flag:
        for i in range(1,n):
                ans.append([i,i+1])
else:
        for i in range(n,1,-1):
                ans.append([i,i-1])

print(len(ans))
for num in ans:
        print(str(num[0])+" "+str(num[1]))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;

const int maxN = 510;
const int maxM = 250010;
int g[maxN][maxN];
int f[maxN][maxN];
int n,m,Q;
struct tmp
{
	int x,y,len;
};
tmp path[maxM];
bool cmp(tmp u,tmp v)
{
	return u.len < v.len;
}
int main()
{
	scanf("%d %d %d",&n,&m,&Q);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d %d",&x,&y);
		g[x][y] ++;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j = 1;j<=n;j++)
		{
			int k = j+i-1;
			if(k<1 || k >n) continue;
			f[j][k] = f[j+1][k] + f[j][k-1] - f[j+1][k-1] + g[j][k];
		}
	}
	for(int i=1;i<=Q;i++)
	{
		int x,y;
		scanf("%d %d",&x,&y);
		printf("%d\n",f[x][y]);
	}
	return 0;
}

Measured memory_bytes: 3840
n=int(input())
d = [input().split() for l in range(n)]
ans='No'
con=0
for i in range(n-2):
    if d[i][0]==d[i][1]:
        if d[i+1][0]==d[i+1][1]:
            if d[i+2][0]==d[i+2][1]:
                ans="Yes"


print(ans)

Measured memory_bytes: 9220
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int a[1000000];
int main()
{
    int k,s;
    int i,j;
    scanf("%d%d",&k,&s);
    for(i=0;i<=k;i++)
    {
        for(j=0;j<=k;j++)
        {
            a[5000+i+j]++;
        }
    }
    int sum=0;
    for(i=0;i<=k;i++)
    {
        int x=s-i;
        if(x<0)continue;
        sum+=a[5000+x];
    }
    printf("%d\n",sum);
    return 0;
}


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

vector<int> G[200];
 
int main(){
    int N,M;
    cin >> N >> M;
    long long sum = 0;
    map<long long,long long> m;
    m[sum % M]++;
    rep(i,N){
        int A;
        cin >> A;
        sum += A;
        m[sum % M]++;
    }
    long long res = 0;
    for(auto it = m.begin();it != m.end();it++){
        res += it->second * (it->second - 1) / 2;
    }
    cout << res << endl;
 
    return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define re register
#define LL long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
inline int read() {
	char c=getchar();int x=0;while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-48,c=getchar();return x;
}
const LL inf=1e16;const int maxn=2005;
struct E{int v,nxt;}e[maxn<<1];char S[maxn];
int n,num,head[maxn],vis[maxn],s[maxn];LL ans,dp[maxn];
inline void add(int x,int y) {
	e[++num].v=y;e[num].nxt=head[x];head[x]=num;
	e[++num].v=x;e[num].nxt=head[y];head[y]=num;
}
LL dfs(int x,int fa) {
	s[x]=vis[x];
	LL mx=0,sum=0;int son=0;
	for(re int i=head[x];i;i=e[i].nxt) {
		if(e[i].v==fa) continue;
		LL t=dfs(e[i].v,x);
		s[x]+=s[e[i].v];t+=s[e[i].v];
		if(t>mx) mx=t,son=e[i].v;
		sum+=t;
	}
	//mx+=s[son];
	if(mx<=sum-mx) dp[x]=sum&1ll;
	else {
		if(dp[son]+s[son]<=sum-mx) dp[x]=sum&1ll;
		else dp[x]=dp[son]+s[son]+mx-sum; 
	}
	return sum;
}
int main() {
	n=read();scanf("%s",S+1);ans=inf;
	for(re int i=1;i<=n;i++)vis[i]=S[i]-'0';
	for(re int x,y,i=1;i<n;i++)add(read(),read());
	for(re int i=1;i<=n;i++) {
		LL tot=dfs(i,0);
		if(dp[i]) continue;
		ans=min(ans,tot>>1ll);
	}
	if(ans==inf)puts("-1");else printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 512
n = int(input())
s = []
for i in range(n):
	s.append(input())

ans = 0
for i in s:
	ans += i.count("AB")

# print(ans)

A = 0
B = 0
AB = 0

for i in s:
	if i[0] == 'B' and i[-1] == 'A':
		AB += 1
	elif i[0] == 'B':
		B += 1
	elif i[-1] == 'A':
		A += 1

if AB == 0:
	ans += min(A,B)
else:
	ans += AB + min(A,B) + (-1 if (A+B) == 0 else 0)

print(ans)

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

int main(){  
  int t,n;
  char suit;
  bool array[4][14] = {false};
  cin >> n;
  for (int i = 0; i < n; i++){
    cin >> suit >> t;
    if (suit == 'S') array[0][t] = true;
    if (suit == 'H') array[1][t] = true;
    if (suit == 'C') array[2][t] = true;
    if (suit == 'D') array[3][t] = true;
  }
  for (int i = 0; i <= 3; i++){
    for (int j = 1; j <= 13; j++){
      if (array[i][j]) continue;
      if (i == 0) cout << 'S' << ' ' << j << endl;
      if (i == 1) cout << 'H' << ' ' << j << endl;
      if (i == 2) cout << 'C' << ' ' << j << endl;
      if (i == 3) cout << 'D' << ' ' << j << endl;
    } 
  }
  return 0;
}


Measured memory_bytes: 3084
// atcoder/abc126/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

const int N = 1e5 + 5;
vector<pair<int, int>> g[N];

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    fill(g, g + N, vector<pair<int, int>>());
    for (int i = 0; i < n - 1; ++i) {
      int a, b, c;
      cin >> a >> b >> c;
      --a;
      --b;
      g[a].push_back({b, c % 2});
      g[b].push_back({a, c % 2});
    }

    map<int, int> color;
    function<void(int, int, int)> rec = [&] (int curr, int prev, int x) {
      color[curr] = x;
      each (e, g[curr]) {
        int next = e.first;
        if (next == prev) continue;
        rec(next, curr, x ^ e.second);
      }
      return ;
    };
    rec(0, -1, 0);

    for (int i = 0; i < n; ++i) {
      cout << color[i] << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 13952
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf (int)(1e18)

bool can(int N, int K, vector<int> &A, vector<int> &F, int x){
	int i;
	for(i = 0; i < N; i++){
		int a = A[i], f = F[N - 1 - i];
		if(a * f <= x){
			continue;
		}
		else{
			K -= a - x / f;
		}
	}
	if(K >= 0){
		return true;
	}
	else{
		return false;
	}
}

signed main(){
	int N, K, i;
	scanf("%lld%lld", &N, &K);
	vector<int> A(N), F(N);
	for(i = 0; i < N; i++){
		scanf("%lld", &A[i]);
	}
	for(i = 0; i < N; i++){
		scanf("%lld", &F[i]);
	}
	sort(A.begin(), A.end());
	sort(F.begin(), F.end());
	int l = -1, h, r = inf;
	while(r - l > 1){
		h = (l + r) / 2;
//		printf("h = %lld\n", h);
		if(can(N, K, A, F, h)){
//			printf("test3\n");
			r = h;
		}
		else{
//			printf("test4\n");
			l = h;
		}
	}
	printf("%lld\n", r);
	return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
int main(void)
{
	int a,x=0,y=0,i;
	for(i=0; i<3; i++)
	{
		scanf("%d", &a);
		if(a==5)
		x++;
		if(a==7)
		y++;
	}
	if(x==2&&y==1)
	printf("YES\n");
	else
	printf("NO\n");
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    int n, m;
    cin>>n>>m;
    vi cnt(n);
    rep(i, m) {
        int v1, v2;
        cin>>v1>>v2; v1--; v2--;
        cnt[v1]++;
        cnt[v2]++;
    }
    rep(i, n) cout<<cnt[i]<<endl;
}

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

int main(){
    ll A, B, C;
    cin >> A >> B >> C;
    ll mx = max({A,B,C});
    ll mn = min({A,B,C});
    ll md = A+B+C-mx-mn;
    ll ans = (mx - md); // +1
    if((md - mn) % 2 == 0){
        ans += (md-mn)/2;
    }else{
        ans += (md-mn)/2 + 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
n = int(input())
s = input()

r = s.count('R')
g = s.count('G')
b = s.count('B')

counts = 0
for i in range(n):
  for j in range(i+1, n):
    k = 2*j-i
    if(k >= n):
      break
    if(s[i] != s[j] and s[j]!=s[k] and s[k]!=s[i]):
      counts += 1
print(r*g*b - counts)


Measured memory_bytes: 27032
#include <stdio.h>
 
using namespace std;
 
void outPut(int Array[],char mark){
    for(int i = 1; i <= 13; i++){
        if(Array[i] == 0) printf("%c %d\n",mark,i);
    }
}
 
int main(){
    char mark[2];
    int n,S[14],H[14],C[14],D[14],tmp;
    for(int i = 0; i < 14; i++) S[i] = H[i] = C[i] = D[i] = 0;
    scanf("%d",&n);
 
    for(int i = 0; i < n; i++){
        scanf("%s %d",mark,&tmp);
        switch(mark[0]){
        case 'S':
            S[tmp] = 1;
            break;
        case 'H':
            H[tmp] = 1;
            break;
        case 'C':
            C[tmp] = 1;
            break;
        case 'D':
            D[tmp] = 1;
            break;
        }
    }
    outPut(S,'S');
    outPut(H,'H');
    outPut(C,'C');
    outPut(D,'D');
}






Measured memory_bytes: 2688
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 2e5 + 5;
 
int n, k, a[N], used[N], cnt = 0;
long long f[N], bit[N];
vector <pair <long long, int> > comp;
 
void update (int x, int val) {
    for (int i = x; i < N; i += i & -i) bit[i] += val;
}
 
long long get (int x) {
    long long ans = 0;
    for (int i = x; i > 0; i -= i & -i) ans += bit[i];
    return ans;
}
 
signed main(){
    scanf("%d %d", &n, &k);
    long long ans = 0;
 
    f[0] = 0;
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) f[i] = f[i - 1] + a[i];
    for (int i = 1; i <= n; i++) comp.push_back(make_pair(f[i] - 1LL * k * i, i));
    comp.push_back(make_pair(0, 0));
 
    sort(comp.begin(), comp.end());
    used[comp[0].second] = ++cnt;
    for (int i = 1; i < comp.size(); i++) {
        if (comp[i].first > comp[i - 1].first) used[comp[i].second] = ++cnt;
        else used[comp[i].second] = cnt;
    }
 
    for (int i = 1; i <= n; i++) {
        update(used[i - 1], 1);
        ans += get(used[i]);
    }
 
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 9584
/*
 * firehawk ~~~> 4d!ty@
 * from: INDIAN INSTITUTE OF TECHNOLOGY INDORE
 * *******************************************
 */

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

#define f 	first
#define s 	second
#define pp 	push
#define pb 	push_back
#define pf 	push_front
#define mp 	make_pair

typedef long long int 	lld;
typedef long double 	ldb;
typedef vector<int> 	vi;
typedef vector<lld> 	vl;
typedef pair<int,int> 	pii;
typedef pair<lld,lld> 	pll;
typedef map<int,int> 	mii;
typedef map<lld,lld> 	mll;
typedef set<int> 	si;
typedef set<lld> 	sl;
typedef vector<pii> 	vii;
typedef vector<pll> 	vll;

#define pi(x) 	printf("%d", x)
#define gi(x) 	scanf("%d", &x)
#define gl(x) 	scanf("%lld", &x)
#define pl(x) 	printf("%lld", x)
#define g64(x) 	scanf("%I64d", &x)
#define p64(x) 	printf("%I64d", x)
#define gc(x)	scanf("%c", &x)
#define pc(x)	printf("%c", x)
#define nl 	printf("\n")
#define sp 	printf(" ")

#define all(c) c.begin(),c.end()
#define tr(it,c) for(__typeof(c.begin()) it = c.begin(); it!=c.end(); ++it)
#define fre freopen("output.txt","wt",stdout);freopen("input.txt","rt",stdin)
#define dbg(x) cerr << #x << " = " << x << endl

template <typename T> vector<T> readVector(int n) { 
	vector<T> res(n); 
	for (int i = 0 ; i < n ; i++) cin >> res[i]; 
	return res; 
}

template <typename T> void printVector(vector <T> in) { 
	int n = in.size();
	for (int i = 0 ; i < n ; i++){
		cout << in[i] << " \n"[i==n-1];
	} 
}

#define INF 1e9
#define MAX 100010
const lld mod = 1e9 + 7;

main(){
	lld w, h;
	cin >> w >> h;
	vll p(w+h);
	lld x;
	lld cntr = 0;
	for(int i = 0; i < w; i++){
		cin >> x;
		p[cntr].f = x;
		p[cntr++].s = 1;
	}
	for(int i = 0; i < h; i++){
		cin >> x;
		p[cntr].f = x;
		p[cntr++].s = 2;
	}
	sort(all(p));
	lld cost = 0, total = 0, tmp, tar = w*h+w+h;
	lld a = w+1, b = h+1;
	for(auto j: p){
		if(j.s==1){
			total += b;
			cost += b*j.f;
			a--;
		}
		if(j.s==2){
			total += a;
			cost += a*j.f;
			b--;
		}
		if(total == w*h+w+h) break;
	}
	cout << cost << endl;
}


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

#define DEBUG1  false
#define DEBUG2  false

int main()
{
    std::vector<std::string> S;

    int N, L;
    std::cin >> N >> L;
    while (N)
    {
        std::string s;
        std::cin >> s;
        S.push_back(s);
        N--;
    }
#if DEBUG1
    std::cout << "DEBUG1: S:";
    for (auto itr = S.begin(); itr != S.end(); ++itr)
    {
        std::cout << " " << *itr;
    }
    std::cout << std::endl;
#endif // DEBUG1

    std::sort(S.begin(), S.end());
#if DEBUG2
    std::cout << "DEBUG2: S:";
    for (auto itr = S.begin(); itr != S.end(); ++itr)
    {
        std::cout << " " << *itr;
    }
    std::cout << std::endl;
#endif // DEBUG2

    for (auto itr = S.begin(); itr != S.end(); ++itr)
    {
        std::cout << *itr;
    }
    std::cout << std::endl;

	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("O2147483647")
//#pragma GCC optimize("inline")
//#pragma GCC optimize("-ffast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("inline-small-functions")
//#pragma GCC optimize("-finline-small-functions")
//#pragma GCC optimize("-fexpensive-optimizations")
//#pragma GCC optimize("-funsafe-loop-optimizations")
//#pragma GCC optimize("inline-functions-called-once")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx,avx")
//#pragma GCC optimze("fast-math")
//#define GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include "testlib.h"
#define rep(i, j, k) for (int i = (int)(j); i<(int)(k); i++)
#define per(i, j, k) for (int i = (int)(k); i>=(int)(j); i--)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)((x).size())
#define fprd fprintf(stderr,
#define fi first
#define se second
#define endl '\n'
using namespace std;
typedef long long ll;
//#define int ll
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;

int main() {
    int h,a;
    scanf("%d%d",&h,&a);
    printf("%d\n",(int)ceil(1.0*h/a));
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
//double speed(double a);
int main(void) {
	int x=0, y=0;
	string str;
	cin >> str;
	for (int i = 0; i < str.length(); i++) {
		if (str[i] == '0')	x++;
		else if (str[i] == '1')	y++;
	}
	printf("%d", 2*min(x, y));
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
#define req(i,n) for(int i = 1;i <= n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a)  (a).begin(),(a).end()
#define fix  fixed << setprecision(10)
const int MOD = 1000000007;
const ll INF = (1LL << 60);
string s,t; ll n,m, q, ans = 0, sum;
bool f = true;
int main() {
    cin >> n; vector<int> a(n + 1,0);
    req(i, n - 1) {
        cin >> m;
        a[m]++;
    }
    req(i, n) {
        cout << a[i] << endl;
    }
}

Measured memory_bytes: 4052
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#define MOD_P 1000000007
#define ll long long
using namespace std;



int main()
{
	int r;
	cin >> r;

	printf("%d", 3 * r * r);

	return 0;
}

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

int main() {
	int coin500, coin100, coin50, total, count=0;

	cin >> coin500 >> coin100 >> coin50 >> total;

	for (int i = 0; i <= coin500; i++) {
		for (int j = 0; j <= coin100; j++) {
			for (int k = 0; k <= coin50; k++) {
				if ((500 * i + 100 * j + 50 * k) == total) {
					count++;
				}
			}
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
(loop :with n := (read-line)
      :for s :upto (length n)
      :for k :on (concatenate 'list n "0000000")
      :for dp :on (cons 1 (loop :repeat (+ (length n) 6) :collect 0))
      :with j := (loop :for x :in '("dream" "dreamer" "erase" "eraser")
                       :collect (concatenate 'list x))
      :if (char= #\0 (car k))
        :if (= 1 (car dp)) :do (princ "YES")
          :else :do (princ "NO")
      :if (= 1 (car dp))
        :if (equal (subseq k 0 5) (car j)) :do (setf (elt dp 5) 1) :end :and
        :if (equal (subseq k 0 7) (cadr j)) :do (setf (elt dp 7) 1) :end :and
        :if (equal (subseq k 0 5) (caddr j)) :do (setf (elt dp 5) 1) :end :and
        :if (equal (subseq k 0 6) (cadddr j)) :do (setf (elt dp 6) 1))

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  ll D;
  scanf("%lld", &D);

  switch (D) {
    case 25:
      cout << "Christmas" << endl;
      break;
    case 24:
      cout << "Christmas Eve" << endl;
      break;
    case 23:
      cout << "Christmas Eve Eve" << endl;
      break;
    case 22:
      cout << "Christmas Eve Eve Eve" << endl;
      break;
  }
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
#a, b = map(int,input().split())
S = input()
F = [False] * 4
n = len(S)
flg = False
V = ["E", "W", "N", "S"]
for i in range(n):
    s = S[i]
    F[V.index(s)] = True

if not (F[0]^F[1]):
    if not (F[2]^F[3]):
        flg = True
a = True
b=  False
c=False
if flg:
    print("Yes")
else:
    print("No")

#print(a^b, b^c)


Measured memory_bytes: 9000
N = int(input())
List_ans = []

for i  in range(1, int(N**(1/2))+1):
    if N % i == 0:
        List_ans.append(i)
        
x = max(List_ans)
y = N//x

Ans = (x-1) + (y-1)
print(Ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <list>
using namespace std;

int main() {
  int n;
//  cin >> n;
  scanf("%d", &n);
  list<int> l;
  for(int i = 0; i < n; i++){
    string command;
    cin >> command;
    if(command == "insert"){
      int x;
//      cin >> x;
      scanf("%d", &x);
      l.push_front(x);
    }
    else if(command == "deleteFirst") l.pop_front();
    else if(command == "deleteLast") l.pop_back();
    else if(command == "delete"){
      int x;
//      cin >> x;
      scanf("%d", &x);
      for(auto it = l.begin(); it != l.end(); it++) if(*it == x){
        l.erase(it);
        break;
      }
    }
  }
  for(auto it = l.begin(); it != l.end(); it++) {
    if(it != l.begin()) cout << " ";
    cout << *it;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 34472
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datX) = readLine.split(" ").map(_.toLong)
    //println(datX)

    var year = 0L
    var money = 100L
    while (money < datX) {
      money += money / 100
      year += 1
      //println(year + " " + money)
    }

    println(year)
  }
}


Measured memory_bytes: 54824
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        String[] lines = getStdin();
        
        String str;
        String[] str1;
        int ver;
        int par;

        for (int i = 0; i < lines.length; i++){
            str = lines[i];
            str1 = str.split(" ");
            ver = Integer.parseInt(str1[0]);
            par = Integer.parseInt(str1[1]);

            for (int j = 0; j < ver; j++){
                for (int k = 0; k < par; k++){
                    System.out.print("#");
                }  System.out.println();
            }
            if(i != lines.length - 1){
                System.out.println();
            }
            
            
            if (ver == 0 && par == 0){
                return;
            }  

        }
    }

  
  private static String[] getStdin() {
    Scanner scanner = new Scanner(System.in);
    ArrayList<String> lines = new ArrayList<>();
    while (scanner.hasNext()) {
      lines.add(scanner.nextLine());
    }
    return lines.toArray(new String[lines.size()]);
  }
  
}





Measured memory_bytes: 37644
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=40;
int p=(int)1e9+7;
int base=31;
int pw[N];
int add(int x,int y,int mod)
{
  x+=y;
  if(x>=mod) x-=mod;
  return x;
}
int mult(int x,int y,int mod)
{
  ll tmp=(ll)x*y;
  if(tmp>=mod) tmp%=mod;
  return tmp;
}
int pow1(int x,int y,int mod)
{
  int ans=1;
  while(y)
    {
      if(y&1) ans=mult(ans,x,mod);
      x=mult(x,x,mod);
      y>>=1;
    }
  return ans;
}
map<ii,int> m;
int calc(string s)
{
  int tmp=0;
  rep(i,0,sz(s)) tmp=add(tmp,mult(pw[i],1+(int)(s[i]-'a'),p),p);
  return tmp;
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  pw[0]=1;
  rep(i,1,N) pw[i]=mult(pw[i-1],base,p);
  int n;
  string s;
  cin>>n>>s;
  rep(i,0,(1<<n))
    {
      string red,blue;
      rep(j,0,n)
	{
	  if(i&(1<<j)) red+=s[j];
	  else blue+=s[j];
	}
      reverse(all(blue));
      int h1=calc(red),h2=calc(blue);
      m[mp(h1,h2)]++;
    }
  ll ans=0;
  rep(i,0,(1<<n))
    {
      string red,blue;
      rep(j,n,2*n)
	{
	  if(i&(1<<(j-n))) red+=s[j];
	  else blue+=s[j];
	}
      reverse(all(blue));
      int h1=calc(red),h2=calc(blue);
      ans+=m[mp(h2,h1)];
    }
  cout<<ans<<endl;
  return 0 ;
}


Measured memory_bytes: 33024
#include <stdio.h>
#include <string.h>
int main(void)
{
    char angou[1000],i;
    scanf("%s",&angou);
    for(i=0;i<strlen(angou);i++)
    {
        angou[i]-=3;
        if(angou[i]<65)
            angou[i]+=26;
    }
    printf("%s\n",angou);
    return 0;
}

Measured memory_bytes: 524
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        if(n<1200){
            System.out.println("ABC");
        }
        else if(n>=1200 && n<2800){
            System.out.println("ARC");
        }
        else if(n>=2800 && n<=4208){
            System.out.println("AGC");
        }
    }
}

Measured memory_bytes: 22868
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int a,b;
  cin >> a >> b;
  rep(i,1251){
    if(int(i*0.08)==a&&int(i*0.1)==b){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100003;
int n,a[MaxN];

int main() {
    scanf("%d",&n);
    for (int i=1;i<=n;++i) scanf("%d",a+i);
    sort(a+1,a+n+1,greater<int>());
    int mx1=0,mx2=0;
    for (int i=1;i<n;++i) {
        if (a[i+1]==a[i]) {
            if (!mx1) mx1=a[i];
            else if (!mx2) mx2=a[i];
            i++;
        }
    }
    printf("%lld\n",(long long)mx1*mx2);
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

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

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
int main(){
    int h,w;cin>>h>>w;
    vector<string>s(h);
    rep(i,h)cin>>s[i];
    queue<P>que;
    int d_max = 0;
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='#')continue;
            vector<vector<int>>d(h,vector<int>(w,INF));
            d[i][j] = 0;
            que.emplace(i,j);
            while(!que.empty()){
                P p = que.front();que.pop();
                int y = p.first,x = p.second;
                rep(i,4){
                    int ny = y+dy[i],nx = x+dx[i];
                    if(ny<0 || ny>=h || nx<0 || nx>=w)continue;
                    if(s[ny][nx]=='#')continue;
                    if(d[ny][nx]<=d[y][x]+1)continue;
                    d[ny][nx] = d[y][x]+1;
                    d_max = max(d[ny][nx],d_max);
                    que.emplace(ny,nx);
                }
            }
        }
    }
    cout<<d_max;
}



Measured memory_bytes: 256
/*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog oi.ender-zzm.pro
*/
#include <bits/stdc++.h>
using namespace std;

template<class T>
inline void read(T &a) {
    register T x = 0, flag = 1;
    register char ch;
    while (!isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), isdigit(ch = getchar()));
    a = x * flag;
}

template <class T>
inline void write(T x) {
    if (x < 0)
        putchar('-'), x = -x;
    if(x >= 10) write(x / 10); 
    putchar(x % 10 + '0');
}

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define For(i, a, b) for (int i = (a); i <= (b); i++) 
#define Rep(i, a, b) for (int i = (a); i >= (b); i--) 
#define For_edge(x) for (int i = head[x]; i; i = net[i])
#define mem0(a) memset(a, 0, sizeof a)

const int maxn = 1e5 + 20;
int n;
#define eps 1e-7
unsigned long long a[maxn];
int main() {
	read(n);
	For (i, 1, n) read(a[i]);
	For (i, 1, n) if (a[i] == 0) {
		cout << 0; return 0;
	}
	unsigned long long ans = 1;
	For (i, 1, n) {
		if (double(ans) - ((double)1e18 / (double) a[i]) > eps) {
			cout << -1 << endl;
			return 0;
		}
		ans = ans * a[i];
	}
	if (ans > (long long) 1e18) cout << -1 << endl;
	else cout << ans << endl;
}


Measured memory_bytes: 4412
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<string>
#include<utility>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N, M;
	cin >> N >> M;
	vector<pair<pair<int, int>, int>>A(M);

	for (int i = 0; i < M; i++) {
		int P, Y;
		cin >> P >> Y;
		A[i] = make_pair(make_pair(P, Y), i);
	}

	sort(A.begin(), A.end());
	vector<pair<int, int>> ans(M);
	int cnt = 1;

	for (int i = 0; i < M; i++) {
		int P = A[i].first.first;
		int ID = A[i].second;
		if (i >= 1 && P == A[i - 1].first.first) {
			cnt++;
		}
		else {
			cnt = 1;
		}
		ans[ID] = make_pair(P, cnt);
	}

	for (int i = 0; i < M; i++){
		cout << setw(6) << setfill('0') << ans[i].first;
		cout << setw(6) << setfill('0') << ans[i].second << endl;
	}


	return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#include<string>
    
using namespace std;
            
    #define ll long long
    #define do long double
    #define ff first
    #define ss second
    #define pb push_back
    #define mp make_pair
    #define inf LONG_LONG_MAX
    #define mod 998244353
    #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);


void solve()
{
	ll n,m,i,j,k;
	cin>>n>>k;
	map<char,ll> fr;
	cin>>fr['s']>>fr['p']>>fr['r'];
	string s;
	cin>>s;
	ll ans=0;
	for(i=0;i<k;i++)
	{
		string t="";
		for(j=i;j<n;j+=k)
		{
			t+=s[j];
		}
		
		ll sum=0;
		j=0;
		//cout<<t<<"  ";
		while(j<t.size())
		{
			m=j;
			ll c=0;
			while(j<t.size() && t[m]==t[j])
			{
				c++;
				j++;
			}
			//cout<<s[m]<<"- ";
			sum+=fr[t[m]]*((c+1)/2);
			//cout<<sum<<" ";
		}
		//cout<<"\n";

		ans+=sum;
	}
	cout<<ans;
	

	
}



int main()
{
    FAST
    ll n,m,i,j;
    ll q;
    q=1;

    while(q--)
    	solve();
	

}

Measured memory_bytes: 640
#include<stdio.h>

int main(void)
{
	int i,j,n,temp,minj,count = 0;
	int A[100];
	
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf("%d",&A[i]);
	}
	for(i = 0;i < n;i++){
		minj = i;
		for(j = i;j < n;j++){
			if(A[j] < A[minj]){
				minj = j;
			}
		}
		if(i != minj)count++;
		temp = A[i];
		A[i] = A[minj];
		A[minj] = temp;
	}
	for(i = 0;i < n;i++){
		if(i != 0 && i < n)printf(" ");
		printf("%d",A[i]);
	}
	printf("\n");
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <string.h>
using namespace std;

#define int long long
const int N = 2e5+5, MOD = 1e9 + 7;
int h, w, a, b;
int fac[N+5], invFac[N + 5], inv[N + 5];

void calcInv()
{
    inv[0] = inv[1] = 1;
    for (int i = 2; i <= N; i++)
    {
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
    }
}
void calcInvFac()
{
    invFac[0] = invFac[1] = 1;
    for (int i = 2; i <= N; i++)
    {
        invFac[i] = (invFac[i-1] * inv[i])%MOD;
    }
}
void calcFac()
{
    fac[0] = 1;
    for (int i = 1; i <= N; i++)
    {
        fac[i] = (fac[i-1]*i % MOD)%MOD;
    }
}

int nCrMOD(int n, int k)
{
    if (k > n || n <= 0 || k <= 0) return 1;
    return ((fac[n] * invFac[k])%MOD * invFac[n-k]) % MOD;
}

signed main()
{
    int ans = 0;
    cin >> h >> w >> a >> b;
    calcInv();
    calcInvFac();
    calcFac();
//    cout << fac[3] << ' ' << invFac[3] << ' ' << invFac[0] << endl;
    for (int i = 1; i <= h-a; i++)
    {
        ans = (ans + (nCrMOD(b+i-2,b-1)*nCrMOD(w-b+h-i-1,w-b-1))%MOD)%MOD;
  //      cout << b+i-2 << ' ' << b-1 << ' ' << nCrMOD(b+i-2,b-1) << ' ' << nCrMOD(w-b+h-i-1,w-b-1) << endl;
    }
    cout << ans;
}


Measured memory_bytes: 4992
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);
            int C = int.Parse(input[2]);

            int kaisuu = B / A;

            if (kaisuu > C)
            {
                Console.WriteLine(C);
            }
            else
            {
                Console.WriteLine(kaisuu);
            }
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  string s;
  cin >> n >> s;
  mat dp(n+1,vec(n+1));
  for(ll i=0;i<n;i++) dp[0][i]=1;
  for(ll i=0;i<n;i++) {
    vec sum(n+10);
    for(ll j=0;j<n-i;j++) {
      sum[j+1]=(sum[j]+dp[i][j])%mod;
    }
    if(s[i]=='<') {
      for(ll j=0;j<n-i;j++) {
        dp[i+1][j]=(sum[n-i]-sum[j+1]+mod)%mod;
      }
    }
    else {
      for(ll j=0;j<n-i;j++) {
        dp[i+1][j]=sum[j+1];
      }
    }
  }
  cout << dp[n-1][0] << endl;
}

Measured memory_bytes: 70784