akhauriyash/Code-Regression huggingface dataset:
import qualified Data.ByteString.Char8 as B
import qualified Data.IntSet as S
import qualified Data.Array.IArray as A
import Data.Maybe
import Data.Bool

main = do
  [n,_] <- map read . words <$> getLine
  es <- readUndirectedEdge <$> B.getContents
  let g = buildG n es
  putStrLn $ bool "IMPOSSIBLE" "POSSIBLE" (voyage n g)

voyage n g = S.foldr' (\x acc -> S.member n (from g x) || acc) False (from g 1)

type Vertex = Int
type Vertexes = S.IntSet
type Edge = (Vertex, Vertex)
type Graph = A.Array Vertex Vertexes

buildG :: Int -> [Edge] -> Graph
buildG n = A.accumArray (flip S.insert) S.empty (1, n)

from :: Graph -> Vertex -> Vertexes
from g = (g A.!)

readUndirectedEdge :: B.ByteString -> [Edge]
readUndirectedEdge = concatMap (constructTwoWay . map readInt . B.words) . B.lines

constructTwoWay :: [Int] -> [Edge]
constructTwoWay [s,t] = [(s, t), (t, s)]
constructTwoWay _ = undefined

readInt :: B.ByteString -> Int
readInt = fst . fromJust . B.readInt


Measured memory_bytes: 57724
N = int(input())
l = [(int(input())-1) for _ in range(N)]
flag = [0]*N
flag[0] = 1
flag[1] = 2
cnt = 0
cur_b = 0
while True:
    cnt += 1
    next_b = l[cur_b]
    if flag[next_b] == 1:
        print(-1)
        break
    elif flag[next_b] == 2:
        print(cnt)
        break
    else:
        flag[next_b] = 1
        cur_b = next_b
else:print(-1)        


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

int main()
{
	int a, b, v, w, t;
	cin >> a >> v >> b >> w >> t;
	if (w >= v) {
		cout << "NO" << endl;
	}
	else {
		if (v * t >= abs(a - b) + w * t) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3624
N, M, K = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i]+A[i])
    if a[i]+A[i]>K:
        break

for i in range(M):
    b.append(b[i]+B[i])

#print(a)
#print(b)
    
ans =0
j = M

for i in range(N+1):
    if a[i]>K:
        break
    
    while b[j]+a[i] > K :
        j -= 1
    ans = max(ans, i + j)

print(ans)



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

int main(int argc, char const *argv[]) {
  int s,k,cnt=0;
  std::cin >> k >> s;
  for(int i=0; i<=k; i++){
    for(int j=0; j<=k; j++){

        int l=s-i-j;
        if(l>=0 && l<=k) cnt++;

    }
  }

  std::cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define HEAP priority_queue
#define heap(T) priority_queue<T,vector<T>,greater<T> >
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
const int BufferSize=1<<25;
char buffer[BufferSize],*Bufferhead,*Buffertail;
int Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T> inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){c=Getchar();rev|=c=='-';if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	x=rev?-x:x;
	return 1;
}
template<class T>inline void print(T x,const char c){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[10];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
//--------------------------------------head--------------------------------------

const int inf=0x3f3f3f3f;
const int N=100005,M=100005,mod=1e9+7;
inline void ch(int &x,int y){x=(x+y)%mod;}
inline int exp(int x,int y,int mod=::mod){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,ans;
vi g[N];

inline pii dfs(int x,int F=0){
	int b1=0,b2=0,son=0;
	for(int y:g[x]){
		if(y==F) continue;
		pii tmp=dfs(y,x);
		b1+=tmp.FF;b2+=tmp.SS;
		son++;
	}
	if(!son) return mp(0,0);
	if(b1==son){
		if(son==1&&!b2) return mp(1,0);
		return mp(1,1);
	}
	else{
//		debug(x-1);
		if(son==1) return mp(0,0);
		ans+=son-b1-1;
		return mp(1,0);
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int x,y;scanf("%d%d",&x,&y);
		x++;y++;
		g[x].pb(y);g[y].pb(x);
	}
	for(int i=1;i<=n;i++)
		if(g[i].size()==1){
			if(!dfs(g[i][0],i).SS) ans++;
			break;
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long 
signed main() 
{
    IOS;    
    int n;
    cin>>n;
    map<int,int>mp1;
    map<int,int>mp2;
    int maxc1=0;
    int maxc2=0;
    int maxi1=0;
    int maxi2=0;
    for(int i=1;i<=n;i++){
    	int x;
    	cin>>x;
    	if(i%2){
    		mp1[x]++;
    		if(mp1[x]>maxc1){
    			maxc1=mp1[x];
    			maxi1=x;
    		}
    	}
    	else {
    		mp2[x]++;
    		if(mp2[x]>maxc2){
    			maxc2=mp2[x];
    			maxi2=x;
    		}
    	}
    }
    if(maxi1!=maxi2 ||maxc1!=maxc2){
    int ans=0;
    for(auto it=mp1.begin();it!=mp1.end();it++){
    	if(it->first!=maxi1)ans+=it->second;
    }
    for(auto it=mp2.begin();it!=mp2.end();it++){
		if(it->first!=maxi2)ans+=it->second;  
		  }
    if(ans!=0)cout<<ans;
    else{
    	if(*mp1.begin()==*mp2.begin())cout<<n/2;
    	else cout<<0;
    }
}
	else{
		vector<int>v1;
		vector<int>v2;
		 for(auto it=mp1.begin();it!=mp1.end();it++){
    	v1.push_back(it->second);
    }
     for(auto it=mp2.begin();it!=mp2.end();it++){
    	v2.push_back(it->second);
    }
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    int ans1=0;
    int ans2=0;
    for(int i=0;i<v1.size();i++){
    	ans1+=v1[i];
    }
   if(v1.size()>=2) ans1-=v1[v1.size()-2];

    for(int i=0;i<v2.size();i++){
    	ans2+=v2[i];
    }
     if(v2.size()>=2)ans2-=v2[v2.size()-2];
    // cout<<v2.size()<<endl;
    cout<<min(ans1,ans2)+n/2-maxc1;
	}
    
    
    return 0; 
} 


Measured memory_bytes: 10420
S = input()
flag = False
if S[0] == "A" and S[2:len(S)-1].count("C") == 1:
    for i in range(1,len(S)):
        if S.index("C") == i:
            continue
        if S[i].islower() == False:
            flag = False
            break
        else:
            flag = True
if flag:
    print("AC")
else:
    print("WA")




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

int main()
{
    int N;
    cin >> N;
    if(65 <= N && N <= 90) cout << 1 << endl;
    else if(97 <= N && N <= 122) cout << 2 << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 3100
w, h , n = map(int, input().split())
X = 0
Y = 0
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and X < x:
        X = x
    elif a == 2 and w > x:
        w = x
    elif a == 3 and Y < y:
        Y = y
    elif a == 4 and h > y:
        h = y
print((w - X) * (h - Y) if (w - X) > 0 and (h - Y) > 0 else 0)


Measured memory_bytes: 3060
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const N = Number(input[0][0]);
  const M = 10 ** 9 + 7;

  let power = 1;

  for (let i = 1; i <= N; i++) {
    power = (power * i) % M;
  }

  return power;
};

console.log(main(read()));


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

int main(){
    map<int,bool> x;
    int n,t;cin>>n;
    for(int i=0;i<n;i++){
        cin>>t;
        if(x[t]){
            puts("NO");
            return 0;
        }else x[t]=1;
    }
    puts("YES");
    return 0;
}

Measured memory_bytes: 9600
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        boolean takahashiWin;
        while (true) {
            c = c - b;
            if (c <= 0) {
                takahashiWin = true;
                break;
            }
            a = a - d;
            if (a <= 0) {
                takahashiWin = false;
                break;
            }
        }
        if (takahashiWin) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 35744
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll a,b;
        cin>>a>>b;
        ll c;
        c=a+b;
        if(c>=10)
        cout<<"error";
        else
        cout<<c;
    }
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>

using namespace std;

int main()

{

    int a,b,c,d,e,f,g;

    cin >> a;

    cin>> b;

    cin >> c;

    d=(a-b);

    e=(d/c);

    f=(e*c);

    g=(d-f);

    cout << g<< endl;

    return 0;

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int N;
int A[100010];
int ans[100010];

int main() {
	cin >> N;
	A[0] = A[N + 1] = 0;
	reps(i, 1, N + 1) cin >> A[i];
	int sum = 0;
	rep(i, N + 1) {
		sum += abs(A[i + 1] - A[i]);
	}

	reps(i, 1, N + 1) {
		ans[i - 1] = sum - (abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i])) + abs(A[i + 1] - A[i - 1]);
	}

	rep(i, N) printf("%d\n", ans[i]);

	return 0;
}

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

int bubbleSort(int A[], int N){
    int sw = 0;
    bool flag = 1;
    // 一回もスワップが発生しなかったら、終了
    for (int i = 0; flag; i++){
        flag = 0;
        for (int j = N-1; j >= i + 1; j--){
            if (A[j] < A[j-1]){
                swap(A[j], A[j-1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int main(){
    int A[100], N, sw;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];
    
    sw = bubbleSort(A, N);
    
    for (int i = 0; i < N; i++){
        if (i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;
    
    return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int a[200007];
int ball[200007];
int vis[200007];
int main(){
    int n;
    cin>>n;
    int cnt=0;
    for(int i=1;i<=n;++i){
        cin>>a[i];
    }
    int sum=0;
    for(int i=n;i>=1;--i){
        if(ball[i]%2!=a[i]){
            for(int j=1;j*j<=i;++j){
                int x=i%j;
                if(!x){
                    if(i/j!=j)
                        ball[i/j]++;
                    ball[j]++;
                }
            }
            vis[i]=1;
            sum++;
        }
    }
    cout<<sum<<"\n";
    for(int i=1;i<=n;++i){
        if(vis[i])
            cout<<i<<" ";
    }
    return 0;
}


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

int main()
{
	#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
    #endif

    int n,m;
    	cin>>n>>m;
    	int a[m];
    	int f=n;
    	for(int i=0;i<m;i++)
    	{
    		cin>>a[i];
            f=f-a[i];
    	}
    	if(f>=0)
    		cout<<f<<endl;
    	else
    		cout<<"-1"<<endl;	
}	

Measured memory_bytes: 3648
package main

import (
	"fmt"
	"sort"
)

func calc(W int, A []int, p [][]int) {
	w := 0
	v := 0
	q := []int{0, 0, 0}
	for w = 0; w < 2; w++ {
		for i := 0; i < 3; i++ {
			if len(p[i]) > 0 && w == p[i][0] {
				q[w+1]++
				p[i] = p[i][1:]
			}
		}
	}
	for {
		q[0], q[1], q[2] = q[1], q[2], 0
		if q[0]+q[1]+q[2] == 0 {
			w = W
			for i := 0; i < 3; i++ {
				if len(p[i]) > 0 && p[i][0] < w {
					w = p[i][0]
				}
			}
		}
		if w >= W {
			break
		}
		for i := 0; i < 3; i++ {
			if len(p[i]) > 0 && w == p[i][0] {
				q[2]++
				p[i] = p[i][1:]
			}
		}
		A[q[0]+q[1]+q[2]]++
		w++
		v++
	}
	A[0] += w - 2 - v
}

func main() {
	var H, W, N int
	fmt.Scan(&H, &W, &N)
	M := map[int][]int{}
	for i := 0; i < N; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		M[a-1] = append(M[a-1], b-1)
	}
	r := make([]int, 0, len(M))
	for i, c := range M {
		sort.Ints(c)
		r = append(r, i)
	}
	sort.Ints(r)
	A := make([]int, 10)
	h := 0
	v := 0
	q := make([][]int, 3)
	for h = 0; h < 2; h++ {
		if len(r) > 0 && h == r[0] {
			q[h+1] = M[h]
			r = r[1:]
		}
	}
	for {
		q[0], q[1], q[2] = q[1], q[2], nil
		if q[0] == nil && q[1] == nil && q[2] == nil {
			h = H
			if len(r) > 0 {
				h = r[0]
			}
		}
		if h >= H {
			break
		}
		if len(r) > 0 && h == r[0] {
			q[2] = M[h]
			r = r[1:]
		}
		calc(W, A, [][]int{q[0], q[1], q[2]})
		h++
		v++
	}
	A[0] += (H - 2 - v) * (W - 2)
	for _, a := range A {
		fmt.Println(a)
	}
}


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


namespace A_C
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            if (s == "ABC")
            {
                Console.WriteLine("ARC");
            }
            else
            {
                Console.WriteLine("ABC");
            }
        }
    }
}


Measured memory_bytes: 25820
#include <bits/stdc++.h>
using namespace std;
using lint = long long;

signed main(){
  string s; cin >> s;
  bool ok = false;
  for(lint i = 0; i < 3; i++){
    if(s[i] == '7') ok = true;
  }
  if(ok)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>

using ll = long long;
using namespace std;

int main() {
  string S;
  cin >> S;
  ll a = 0, b = 0;
  for (ll i = 0; i < (ll)S.size(); i++) {
    int c = S[i] == '0' ? 0 : 1;
    if (i % 2 == c) a++;
    else b++;
  }
  cout << min(a, b) << endl;
}


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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main(){

  ll n,m,k;cin>>n>>m>>k;

  UnionFind tree(n);
  vector<ll>s(n,0);
  rep(i,0,m){
    ll a,b;cin>>a>>b;
    a--,b--;
    tree.merge(a,b);
    s[a]++;
    s[b]++;
  }
  vector<vector<ll>>e(n);
  rep(i,0,k){
    ll c,d;cin>>c>>d;
    c--,d--;
    e[c].push_back(d);
    e[d].push_back(c);
  }

  rep(i,0,n){
    ll ans=tree.size(i)-1-s[i];
    for(auto u:e[i]){
      if(tree.issame(i,u))ans--;
    }
    cout<<ans<<" ";
  }

  return 0;
}


Measured memory_bytes: 9088
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
struct node
{
	int u,v;
}p[2005];
int n,m,i,j,k,l,id[2005],p1,p2,head[2005],adj[4005],nxt[4005],dep[2005],col[2005],size[2005],son[2005],tp[2005],fa[2005],ans;
bool v[2005];
void dfs(int x,int dad)
{
	id[x]=++i;
	size[x]=1;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad)
		{
			dep[adj[y]]=dep[x]+1;
			fa[adj[y]]=x;
			dfs(adj[y],x);
			size[x]+=size[adj[y]];
			if(!son[x]||size[adj[y]]>size[son[x]])
				son[x]=adj[y];
		}
}
void Dfs(int x,int dad)
{
	if(son[x])
	{
		tp[son[x]]=tp[x];
		Dfs(son[x],x);
	}
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad&&adj[y]!=son[x])
		{
			tp[adj[y]]=adj[y];
			Dfs(adj[y],x);
		}
}
int lca(int a,int b)
{
	while(tp[a]!=tp[b])
	{
		if(dep[tp[a]]<dep[tp[b]])
			swap(a,b);
		a=fa[tp[a]];
	}
	return dep[a]<dep[b]?a:b;
}
int dis(int a,int b)
{
	return dep[a]+dep[b]-2*dep[lca(a,b)];
}
void work(int num)
{
	int i,j,k,x,y,z,p1,p2;
	if(num>=n)
	{
		for(i=1;i<=m;++i)
			col[i]=1;
		return;
	}
	for(i=1,j=0;i<=n;++i)
		if(!v[i]&&(j==0||dep[i]>dep[j]))
			j=i;
	v[j]=true;
	p1=p2=0;
	for(k=1;k<=m;++k)
		if((id[p[k].u]>=id[j]&&id[p[k].u]<id[j]+size[j])!=(id[p[k].v]>=id[j]&&id[p[k].v]<id[j]+size[j]))
		{
			if(!p1)
				p1=k;
			else if(!p2)
				p2=k;
			else
				break;
		}
	if(p1&&p2)
	{
		node a=p[p1],b=p[p2];
		x=(id[a.u]>=id[j]&&id[a.u]<id[j]+size[j]?a.v:a.u);
		y=(id[b.u]>=id[j]&&id[b.u]<id[j]+size[j]?b.v:b.u);
		p[p2]=(node){1,1};
		p[p1]=(node){x,y};
		work(num+1);
		z=col[p1];
		if(a.u==x)
			col[p1]=z;
		else
			col[p1]=(z==1?2:1);
		if(b.v==y)
			col[p2]=z;
		else
			col[p2]=(z==1?2:1);
		p[p1]=a,p[p2]=b;
	}
	else
		work(num+1);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(i=1;i<n;++i)
	{
		scanf("%d%d",&j,&k);
		adj[i*2-1]=k;
		nxt[i*2-1]=head[j];
		head[j]=i*2-1;
		adj[i*2]=j;
		nxt[i*2]=head[k];
		head[k]=i*2;
	}
	for(i=1;i<=m;++i)
		scanf("%d%d",&p[i].u,&p[i].v);
	i=0;
	dfs(1,-1);
	tp[1]=1;
	Dfs(1,-1);
	for(i=1;i<n;++i)
	{
		j=(dep[adj[i*2]]>dep[adj[i*2-1]]?adj[i*2]:adj[i*2-1]);
		p1=p2=0;
		for(k=1;k<=m;++k)
			if((id[p[k].u]>=id[j]&&id[p[k].u]<id[j]+size[j])!=(id[p[k].v]>=id[j]&&id[p[k].v]<id[j]+size[j]))
			{
				if(!p1)
					p1=k;
				else if(!p2)
					p2=k;
				else
					break;
			}
		if(p1)
			++ans;
		if(p2)
			++ans;
	}
	printf("%d\n",ans);
	work(1);
	for(i=1;i<=m;++i)
		if(col[i]==1)
			printf("%d %d\n",p[i].u,p[i].v);
		else
			printf("%d %d\n",p[i].v,p[i].u);
	return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

#define fill(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const int N = 2e6+10;

ll pws[2][N];
ll fc[N];

ll powmod(ll base, ll p) {
    if(p<0) {
        return 0;
    }

    if(p==0){
        return 1;
    }
    if(p==1){
        return base%mod;
    }

    if(p%2==0) {
        ll ans = powmod(base, p/2);
        return ((ans*ans)%mod+mod)%mod;
    }
    else {
        ll ans = powmod(base,p-1);
        return ((ans*base)%mod+mod)%mod;
    }
}

ll moduloinverse(ll n, ll p) {
    return powmod(n,p-2);
}

string s;
int main(){
fast;

int k;
cin >>k;
cin>>s;
int n = s.size();

fc[0] = 1;
for(int i=1;i<=n+k;i++) {
    fc[i] = (fc[i-1]*i)%mod;
}

pws[0][0]=pws[1][0]=1;
for(int i=1;i<=n+k;i++) {
    pws[0][i]=(pws[0][i-1]*25)%mod;
    pws[1][i]=(pws[1][i-1]*26)%mod;
}

ll ans1 = pws[1][n+k];
ll ans2 = 0;
for(int i=0;i<n;i++) {
    ll temp = fc[n+k];
    temp = (temp * moduloinverse(fc[i], mod))%mod;
    temp = (temp * moduloinverse(fc[n+k-i], mod))%mod;
    temp = (temp * pws[0][n+k-i])%mod;

    ans2 = (ans2+temp)%mod;
}

ans1 = (ans1 - ans2)%mod;
if(ans1<0) {
    ans1+=mod;
}
cout<<ans1<<endl;

return 0;
}

Measured memory_bytes: 51200
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int H = sc.nextInt();
   int W = sc.nextInt();

   String[][] men = new String[H][W];
   
   String tmp = "";
   for(int i=0;i<H;i++)
   {
     tmp = sc.next();
     for(int k=0;k<W;k++)
     {
       men[i][k] = tmp.substring(k,k+1);       
     }
   }
   
   boolean[] tate = new boolean[H];
   boolean[] yoko = new boolean[W];
   
   for(int i = 0;i<H;i++)
   {
     tate[i]=false;
     for(int k = 0;k<W;k++)
     {
       if(men[i][k].equals("#")) 
       {
         tate[i]= true;
       	 break;
       }
     }
   }
   
   for(int i = 0;i<W;i++)
   {
     yoko[i]=false;
     for(int k = 0;k<H;k++)
     {
       if(men[k][i].equals("#")) 
       {
         yoko[i]= true;
       	 break;
       }
     }
   }
   
   String anstmp = "";
   for(int i=0;i<H;i++)
   {
     anstmp = "";
     for(int k=0;k<W;k++)
     {
       if(tate[i] && yoko[k]) anstmp+=men[i][k];       
     }
     if(!anstmp.equals("")) System.out.println(anstmp);
   }
   
 }
}

Measured memory_bytes: 30900
S = raw_input()
T = raw_input()

d = {}
z = {}
flag = True
for i in range(len(S)):
    if S[i] not in d:
        d[S[i]] = T[i]
        z[T[i]] = S[i]
    if d[S[i]] != T[i]:
        flag = False

for k in d:
    if z[d[k]] != k:
        flag = False

if flag:
    print 'Yes'
else:
    print 'No'


Measured memory_bytes: 9444
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var num = new int[n];
            for(var i=0;i<n;i++)
            {
                num[i] = int.Parse(Console.ReadLine());
            }
            var index = 1;
            var count = 0;
            while(true)
            {
                index = num[index - 1];
                count++;
                if (count == n) break;
                if (index == 2) break;
            }
            if (count == n) Console.WriteLine(-1);
            else Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 15172
#include <stdio.h>
#include <vector>
#define MAX (10000+2)
using namespace std;
int main(){
    int n, r, x1, x2, y1, y2;
    while(true){
        scanf("%d %d", &n, &r);
        if(n==0 && r==0) break;
        int plane[2][MAX]={0};
        vector<vector<pair<int, int> > > sheets(MAX);
        for(int i=0; i<n; i++){
            scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
            sheets[x1+1].push_back(make_pair(y1+1,+1));
            sheets[x1+1].push_back(make_pair(y2+1,-1));
            sheets[x2+1].push_back(make_pair(y1+1,-1));
            sheets[x2+1].push_back(make_pair(y2+1,+1));
        }
        if(r==2){
            int area=0, length=0;
            for(int x=1; x<MAX; x++){
                for(int i=0; i<MAX; i++){
                    plane[x%2][i]=0;
                }
                for(vector<pair<int, int> >::iterator sheet=sheets[x].begin(); sheet!=sheets[x].end(); sheet++){
                    plane[x%2][(*sheet).first]+=(*sheet).second;
                }
                for(int y=1; y<MAX; y++){
                    plane[x%2][y]+=plane[x%2][y-1];
                }
                for(int y=1; y<MAX; y++){
                    plane[x%2][y]+=plane[(x+1)%2][y];
                    area+=plane[x%2][y]>0 ? 1 : 0;
                    length+=(plane[x%2][y-1]>0)!=(plane[x%2][y]>0) ? 1 : 0;
                    length+=(plane[x%2][y]>0)!=(plane[(x+1)%2][y]>0) ? 1 : 0;
                }
            }
            printf("%d\n%d\n", area, length);
        }else{
            int area=0;
            for(int x=1; x<MAX; x++){
                for(int i=0; i<MAX; i++){
                    plane[x%2][i]=0;
                }
                for(vector<pair<int, int> >::iterator sheet=sheets[x].begin(); sheet!=sheets[x].end(); sheet++){
                    plane[x%2][(*sheet).first]+=(*sheet).second;
                }
                for(int y=1; y<MAX; y++){
                    plane[x%2][y]+=plane[x%2][y-1];
                }
                for(int y=1; y<MAX; y++){
                    plane[x%2][y]+=plane[(x+1)%2][y];
                    area+=plane[x%2][y]>0 ? 1 : 0;
                }
            }
            printf("%d\n", area);
        }
    }
    return 0;
}


Measured memory_bytes: 3176
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct edge
{
	long long to; long long len;
	bool operator<(const edge& rhs) const {
		return len > rhs.len;
	}
};

ll const MAX = 2e4 + 4;
ll w[MAX], s[MAX], v[MAX];
ll dp[1005][MAX] = {};
ll upper[MAX];
bool order(ll x, ll y) {
	return w[x] + s[x] < w[y] + s[y];
}

ll s_max = 0; ll w_max = 0;

int main(){
	ll n; cin >> n;
	REP(i, 1, n) {
		cin >> w[i] >> s[i] >> v[i];
		upper[i] = i;
		s_max = max(s_max, s[i]);
		w_max = max(w_max, w[i]);
	}
	SORT_O(upper, n, order);
	REP(j, 1, s_max + w_max) {
		dp[0][j] = -1e18;
	}
	REP(i, 1, n) {
		ll cur = upper[i];
		REP(j, 0, s_max + w_max) {
			if (j < w[cur] || j - w[cur] > s[cur]) {
				dp[i][j] = dp[i - 1][j];
			}
			else {
				dp[i][j] = max( dp[i - 1][j], dp[i - 1][j - w[cur]] + v[cur] );
			}
		}
	}
	ll ans = 0;
	REP(j, 0, s_max + w_max) {
		ans = max(ans, dp[n][j]);
	}
	cout << ans << endl;
	/*
	REP(i, 1, n) {
		cout << upper[i] << " ";
	}cout << endl;
	REP(i, 0, n) {
		REP(j, 0, s_max + w_max) {
			cout << dp[i][j] << " ";
		}
		cout << endl << endl;
	}
	*/
	
}

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

typedef long long int ll;

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, k;
    cin >> n >> k;
    
    int res = 0;
    while (n)
    {
        ++res;
        n /= k;
    }
    
    cout << res << "\n";

    return 0;
}


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

const int N=100100,mod=998244353;
int x[N],y[N],pw[N],n,ans;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	pw[0]=1;
	for(int i=1;i<=n;++i)pw[i]=pw[i-1]*2%mod;
	for(int i=1;i<=n;++i)cin>>x[i]>>y[i];
	ans=(pw[n]-1+mod-n)%mod;
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j){
			int cnt=0;
			for(int k=j+1;k<=n;++k)
				if((y[k]-y[j])*(x[k]-x[i])==(y[k]-y[i])*(x[k]-x[j]))++cnt;
			ans=(ans-pw[cnt]+mod)%mod;
		}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
typedef long long ll;

double INF = 1e9;

int main() {
  int n, m; cin >> n >> m; vector<int> v[n]; // tiの方
  double an[n]; fill(an, an+n, INF); an[n-1] = 0;
  for(int i=0; i<m; i++) {
    int a, b; cin >> a >> b; a--; b--;
    v[a].push_back(b);
  }
  double anan = 1e16;
  for(int id=n-2; id>=0; id--){
    fill(an, an+n, INF); an[n-1] = 0;
  for(int i=n-2; i>=0; i--) {
    double sm=0, mx=0;
    int lg = v[i].size();
    for(int x:v[i]) {
      sm += an[x] + 1; mx = max(mx, an[x] + 1);
    }
    
    if (id == i && lg >= 2) {
      double ax = (double)sm / (double)lg;
      double bx = (double)((double)sm - (double)mx) / (double)((double)lg - (double)1);
      an[i] = min(ax, bx);
    } else an[i] = (double)sm / (double)lg;
    //an[i] = (double)sm / (double)lg;
    //cout << i << " " << sm << " " << mx << " " << lg << " " << an[i] <<  endl;
  }
    anan = min(anan, an[0]);
  }
  //for(int i=0; i<n; i++) {
  //  cout << an[i] << endl;
  //}
  cout << fixed << setprecision(7);
  cout << anan << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  int n;
  string s;
  cin >> n >> s;
  string t = s;
  sort(ALL(t));
  int c = 0;
  rep(i, n) {
    if (t[i] == 'W') break;
    if (t[i] != s[i]) ++c;
  }
  cout << c << endl;
}

Measured memory_bytes: 3808
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000
#define MAX 200001

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll MOD = 1000000007;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int main(){
    string s;
    cin >> s;
    int n = s.size();
    if(s[n-1] != 's') s += "s";
    else{
        s += "es";
    }
    cout << s << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const int N = 1e7 + 1;
int n, m, k;
long long int cs[N]; 
int main(){
    int n, m;
    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 3600
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    T=ST()

    N = len(S)

    chr_where = defaultdict(list)
    for i,s in enumerate(S):
        chr_where[s].append(i)
    
    cnt = 0 #何度先頭に戻ったか
    now = -1
    for t in T:
        if not chr_where[t]:
            print(-1)
            exit()
        index = bisect_right(chr_where[t], now)
        if index >= len(chr_where[t]):
            now = chr_where[t][0]
            cnt += 1
        else:
            now = chr_where[t][index]
        
    print(cnt*N + now + 1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 46704
/*
   first we need to sort the all edges then updates them one after another .
   we update them according to the adjacent edges then maximize the answer of edge
*/
#include<queue>
#include<map>
#include <string>
#include<bits/stdc++.h>
#define pi 3.141592654
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);
//#define x real()
//#define y imag()
using namespace std;
typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
//typedef complex<double> point;
//template<typename T>T gcd(T x, T y) { if(y == 0)return x; else return gcd(y, x%y); }
//typedef bitset<30> mask;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//#define var(x) ((x)<<1)
//#define nvar(x) ((x)^1)

ll n,m,k,ans,mod=1e9+7;

ll f[200020];
ll fPower(ll b, ll p, ll m){    //O(log(p))
  ll res = 1;
  while(p){
    if(p&1) res = (res * b)%m;
    b = (b * b)%m;
    p >>= 1;
  }
  return res;
}

inline ll modInversePrime(ll a, ll p){     //O(log(p))
  return fPower(a, p-2, p);
}
ll nCr(int n,int r)
{
    return ((f[n]*modInversePrime(f[r],mod))%mod*modInversePrime(f[n-r],mod)+mod)%mod;
}
 main()
{

//cout<<Pow((ll)1000000,(ll)110);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//    char input[15];
//    scanf("%s", &input);  array of char
//  gets(c+1);  array of char
//printf("%s, ",name[k[i]].c_str());  printf of string
input;
cin>>n>>m>>k;
ll c=0;

forr(i,1,n-1)
{
    c+=i;
    ans+=(((m*m)%mod)*(c%mod))%mod;
    ans%=mod;
}
c=0;
forr(i,1,m-1)
{
    c+=i;
    ans+=(((n*n)%mod)*(c%mod))%mod;
    ans%=mod;
}


f[0]=1;
forr(i,1,200002)
f[i]=(f[i-1]*i)%mod;

ans*=nCr(n*m-2,k-2);
ans%=mod;

cout<<(ans+mod)%mod<<endl;


return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
int n,m,l[310000],r[310000],tree[110000];
vector<int> vec[110000];
void add(int x,int y){
    for (;x<=m;x+=x&-x) tree[x]+=y;
}
int getsum(int x){
    int sum=0;
    for (;x;x-=x&(-x)) sum+=tree[x];
    return sum;
}
int main(){
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++){
        scanf("%d%d",&l[i],&r[i]);
        vec[r[i]-l[i]+1].push_back(i);
    }
    for (int i=1;i<=m;i++){
        int ans=0;
        for (int j=0;j<(int)vec[i].size();j++)
            add(l[vec[i][j]],1),add(r[vec[i][j]]+1,-1);
        for (int j=i;j<=m;j+=i) ans+=getsum(j);
        n-=vec[i].size();
        printf("%d\n",ans+n);
    }
    return 0;
}




Measured memory_bytes: 9344
N=int(input())
edge={i:[] for i in range(1,N+1)}
for i in range(0,N-1):
    a,b=map(int,input().split())
    edge[a].append((b,i))
    edge[b].append((a,i))

parent={i:-1 for i in range(1,N+1)}
depth={i:-1 for i in range(1,N+1)}
parent[1]=(0,-1)
depth[1]=0
q=set([1])
sub=set([])
while q:
    while q:
        x=q.pop()
        for b,i in edge[x]:
            if parent[b]==-1:
                parent[b]=(x,i)
                depth[b]=depth[x]+1
                sub.add(b)

        if not q:
            q=sub
            sub=set([])
            break

M=int(input())
condition=[[] for i in range(0,M)]
for i in range(0,M):
    u,v=map(int,input().split())
    ans=set([])
    while depth[u]!=depth[v]:
        if depth[u]>depth[v]:
            U,j=parent[u]
            ans.add(j)
            u=U
        else:
            V,j=parent[v]
            ans.add(j)
            v=V

    while u!=v:
        U,j=parent[u]
        ans.add(j)
        u=U
        V,j=parent[v]
        ans.add(j)
        v=V
    con=0
    for j in ans:
        con+=2**j
    condition[i]=con

ans=2**(N-1)
ban=0
for i in range(1,2**M):
    num=bin(i).count('1')
    s=0
    for j in range(0,M):
        if i>>j &1==1:
            s=s|condition[j]


    n=bin(s).count('1')
    if num%2==1:
        ban+=2**(N-1-n)
    else:
        ban-=2**(N-1-n)

print(ans-ban)

Measured memory_bytes: 42604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<endl
#define AA(i) cout<<i<<endl
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
  int H1,M1,H2,M2,K; cin >> H1>>M1>>H2>>M2>>K;
  int ans = H2*60 + M2 - H1*60 - M1;
  ans -= K;
  AA(ans);
  
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main()
{
    int a, b, c, x, cnt = 0;
    cin >> a >> b >> c >> x;

    for (int i = 0; i <= a; ++i) {
        for (int j = 0; j <= b; ++j) {
            for (int k = 0; k <= c; ++k) {
                if (((i * 500) + (j * 100) + (k * 50)) == x) ++cnt;
            }
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

ll const TMAX =  2*(1e5+2);
ll const CHMAX = 31;

ll cnt[TMAX][CHMAX] = {};

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, c; cin >> n >> c;
    ll s[n], t[n], ch[n];
    rep(i, n){
        cin >> s[i] >> t[i] >> ch[i];
    }


    rep(i, n){
        cnt[2*s[i]-1][ch[i]]++;
        cnt[2*t[i]][ch[i]]--;
    }

    reps(i, 1, TMAX){
        reps(j, 1, CHMAX){
            if(cnt[i-1][j] == 1 && cnt[i][j] == -1){
                cnt[i-1][j] = cnt[i][j] = 0LL;
            }
        }
    }

    reps(j, 1, CHMAX){
        reps(i, 1, TMAX){
            cnt[i][j] = cnt[i-1][j] + cnt[i][j];
            // cout << "ch:" << j << " t:" << fixed << setprecision(1) << double(i)/2.0 << " " << cnt[i][j] << endl;
        }
    }

    ll vmax = 0;
    rep(i, TMAX){
        ll tempmax = 0;
        rep(j, CHMAX){
            tempmax += cnt[i][j];
        }
        vmax = max(vmax, tempmax);
    }

    cout << vmax << endl;

    return 0;
}

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

int main() {
  int N, K, R, S, P;
  string T;
  cin >> N >> K >> R >> S >> P >> T;

  int sum = 0;
  string myhand = "";
  for (int i = 0; i < N; i++) {
    char hand = T.at(i);
    if (hand == 'r') {
      if (i >= K && myhand.at(i - K) == 'p') {
        myhand += 'x';
      } else {
        myhand += 'p';
        sum += P;
      }
    } else if (hand == 's') {
      if (i >= K && myhand.at(i - K) == 'r') {
        myhand += 'x';
      } else {
        myhand += 'r';
        sum += R;
      }
    } else if (hand == 'p') {
      if (i >= K && myhand.at(i - K) == 's') {
        myhand += 'x';
      } else {
        myhand += 's';
        sum += S;
      }
    }
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 3300030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
using namespace std;
int n;

int main(){
cin>>n;
int arr[n];
rep(i,0,n)
cin>>arr[i];
if(n==2)
{
	cout<<abs(arr[1]-arr[0]);
	return 0;
}
int sum=0;
rep(i,0,n)
sum+=arr[i];
int y=n-2;
int s=0;
int ans=100000;
while(y>=0)
{
	s+=arr[y+1];
	sum-=arr[y+1];
	if(abs(s-sum)<ans)
	ans=(abs(s-sum));
	y--;
}
cout<<ans;
}

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

int main() {
  string s;
  cin >> s;
  vector<int> a(2019,0);
  reverse(s.begin(),s.end());
  int now=0;
  int beki=1;
  a[0]++;
  rep(i,s.length()){
    int x=s[i]-'0';
    now+=beki*x;
    now%=2019;
    a[now]++;
    beki=beki*10%2019;
  }
  int ans=0;
  rep(i,2019){
    int x=a[i];
    ans+=(x*(x-1))/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3732
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int N_1 = N % 10;
    
    if ( N_1 ==3)
      System.out.println("bon");
    else if( N_1 == 0 || N_1 == 1 || N_1 == 6 || N_1 == 8)
      System.out.println("pon");
    else
      System.out.println("hon");
  }
}

Measured memory_bytes: 35832
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include <cstdint>
#include<unordered_map>
#include <boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;


int main() {
	int n;
	scanf("%d",&n);
	unordered_map<int, int>a;
	rep(i, n) {
		int m;
		cin >> m;
		if (a[m] == 0) {
			a[m] = 1;
		}
		else {
			a.erase(m);
		}
	}
	cout << a.size() << endl;
}


Measured memory_bytes: 4388
n = io.read('*n')

ans = 1

gcd = function (a, b) if b == 0 then return a else return gcd(b, a % b) end end
lcm = function (a, b) return a // gcd(a, b) * b end

for i = 1, n do ans = lcm(ans, io.read('*n')) end

print(ans)


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

int main(){
  int N;
  cin >> N;
  vector<long long int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  } 
  long long int l=0;
  long long int s=0;
  sort(A.begin(),A.end());
  for(int i=0;i<N-1;i++){
    if(A.at(i)==A.at(i+1)){
      s=l;
      l=A.at(i);
      i++;
    }
  }
  cout << l*s << endl;

  
}

Measured memory_bytes: 1024
let n, y = Scanf.scanf "%d %d" (fun a b -> (a, b))

let rec solve tt =
  let rec aux tt ft =
    if tt + ft > n then None
    else
      let t = n - tt - ft in
      if tt * 10000 + ft * 5000 + t * 1000 = y then Some (tt, ft, t) else aux tt (ft + 1)
  in
  if tt > n then (-1, -1, -1)
  else match aux tt 0 with Some x -> x | None -> solve (tt + 1)


let () =
  let tt, ft, t = solve 0 in Printf.printf "%d %d %d\n" tt ft t

Measured memory_bytes: 384
from collections import deque
import sys
input = sys.stdin.readline


def compress(x1, x2, w):
    N = len(x1)
    xs = set()
    for i in range(N):
        for d in [0, 1]:
            tx1, tx2 = x1[i]-d, x2[i]+d
            if 0 <= tx1 < w:
                xs.add(tx1)
            if 0 <= tx2 < w:
                xs.add(tx2)
    xs = list(xs)
    xs.sort()
    for i in range(N):
        x1[i] = xs.index(x1[i])
        x2[i] = xs.index(x2[i])
    return len(xs)


while True:
    w, h = map(int, input().split())
    if w == h == 0:
        break
    n = int(input())
    x1 = [0] * n
    x2 = [0] * n
    y1 = [0] * n
    y2 = [0] * n
    for i in range(n):
        x1[i], y1[i], x2[i], y2[i] = map(int, input().split())
        x2[i] -= 1
        y2[i] -= 1
    w = compress(x1, x2, w)
    h = compress(y1, y2, h)

    board = [[False] * w for _ in range(h)]
    for i in range(n):
        for y in range(y1[i], y2[i]+1):
            for x in range(x1[i], x2[i]+1):
                board[y][x] = True

    ans = 0
    dx = [0, 1, 0, -1]
    dy = [1, 0, -1, 0]
    for y in range(h):
        for x in range(w):
            if board[y][x]:
                continue
            ans += 1
            queue = deque()
            queue.append((x, y))
            while queue:
                sx, sy = queue.popleft()

                for i in range(4):
                    tx, ty = sx+dx[i], sy+dy[i]
                    if 0 <= tx < w and 0 <= ty < h and not board[ty][tx]:
                        queue.append((tx, ty))
                        board[ty][tx] = True
    print(ans)



Measured memory_bytes: 21388
#include<bits/stdc++.h>
using namespace std;
int gcd(int m,int n){if(m%n==0)return n;else return gcd(n,m%n);}
int num(int a,int b,int c)
{
	if(a==b&&b==c)return 1;
	else if(a==b||b==c||c==a)return 3;
	else return 6;
}
int main()
{
	int n;cin>>n;
	char s[4444];cin>>s;
	long nr=0,ng=0,nb=0;
	for(int i=0;i<n;i++)nr+=s[i]=='R',ng+=s[i]=='G',nb+=s[i]=='B';
	long ans=nr*ng*nb;
	for(int i=0;i<n;i++)for(int d=1;i+d+d<n;d++)if((s[i]^s[i+d]^s[i+d+d])==('R'^'G'^'B'))ans--;
	cout<<ans<<'\n';
}


Measured memory_bytes: 3636
#include <stdio.h>

int main(void) {

  int w, h, x, y, r;

  scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);

  if (x - r >= 0 && x + r <= w && y - r >= 0 && y + r <= h) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}



Measured memory_bytes: 2140