akhauriyash/Code-Regression huggingface dataset:
s=input()
n=len(s)
i=0
cnt=0
ans=0
while i<n:
  if s[i]=='A':
    i+=1
    cnt+=1
    while s[i:i+2]=='BC':
      ans+=cnt
      i+=2
  else:
    cnt=0
    i+=1
print(ans)

Measured memory_bytes: 69236
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	//C問題

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scan = new Scanner(System.in);

		int a, b;

		a = scan.nextInt();
		b = scan.nextInt();

		if (a > 9 || b > 9) {
			System.out.println(-1);
		} else {
			System.out.println(a * b);
		}
	}

}


Measured memory_bytes: 21844
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sparsh Sanchorawala
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ERedScarf solver = new ERedScarf();
        solver.solve(1, in, out);
        out.close();
    }

    static class ERedScarf {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            int n = s.nextInt();
            int[] a = new int[n];
            int xor = 0;
            for (int i = 0; i < n; i++) {
                a[i] = s.nextInt();
                xor ^= a[i];
            }
            for (int i = 0; i < n; i++) {
                a[i] = xor ^ a[i];
            }
            for (int i = 0; i < n; i++)
                w.print(a[i] + " ");
            w.println();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 45304
n, m = map(int, input().split())
hope = []
for i in range(m):
    hope.append(list(map(int, input().split())))
    
hope.sort(key=lambda x:x[1])

last = 100000000
count = 0
for i in hope:
    if(i[0]<=last<i[1]):
        continue
    else:
        last = i[1]-1
        count += 1
        
print(count)

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


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

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key
ll cnt=0;
ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y,ll m){ll res=1; while(y>0){if(y&1) res=(res*x)%m;y=y>>1;x=(x*x)%m;}return res%m;} // modular exponent
const int maxn=2e5+5;
ll dp[maxn];
ll n;
ll steps(ll x)
{
    if(x==0) return 0;
    int ans=0;
    while(x>0)
    {
        ans++;
        ll ppc=__builtin_popcount(x);
        x=x%ppc;
    }
    return ans;
}
void work()
{
  rep(i,maxn)
  {
    dp[i]=steps(i);  
  }
}
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    cin>>n;
    string s;
    cin>>s;
    work();
    // cout<<"yes"; 
    ll len=s.length();
    for(ll i=len-1;i>=0;i--)
    {
      if(s[i]=='1') cnt++;
    }
    // only for cnt+1 and cnt-1
    if(cnt==0)
    {
      rep(i,n)
      {
        cout<<1<<'\n';
      }
      return 0;
    }
    ll cnt1=cnt+1;
    ll num=0;
    for(ll i=len-1,j=0;i>=0;i--,j++)
    {
      num+=(s[i]-'0')*power(2,j,cnt1);
      num%=cnt1;
    }
    if(cnt==1)
    {
      rep(i,n)
      {
        if(s[i]=='1') cout<<0<<'\n';
        else
        {
          num+=(power(2,n-i-1,cnt1));
          num%=cnt1;
          cout<<dp[num]+1<<'\n';
          num-=(power(2,n-i-1,cnt1));
          num+=cnt1;
          num%=cnt1;
        }
      }
      return 0;
    }
    ll cnt2=cnt-1;
    ll num2=0;
    for(ll i=len-1,j=0;i>=0;i--,j++)
    {
      num2+=(s[i]-'0')*power(2,j,cnt2);
      num2%=cnt2;
    }
    rep(i,n)
    {
      if(s[i]=='1')
      {
        num2-=(power(2,n-i-1,cnt2));
        num2+=cnt2;
        num2%=cnt2;
        cout<<dp[num2]+1<<'\n';
        num2+=(power(2,n-i-1,cnt2));
        num2+=cnt2;
        num2%=cnt2;
      }
      else
      {
        num+=(power(2,n-i-1,cnt1));
        num%=cnt1;
        cout<<dp[num]+1<<'\n';
        num-=(power(2,n-i-1,cnt1));
        num+=cnt1;
        num%=cnt1;
      }
    }
    return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


Measured memory_bytes: 5324
import sys
sys.setrecursionlimit(10**9)

N = int(input())
h = list(map(int,input().split()))

memo = [-1]*N

def calc_cost(i):
  if memo[i] != -1:
    return memo[i]
  
  if i == 0:
    return 0
  elif i == 1:
    return abs(h[0]-h[1])
  
  a = calc_cost(i-1)+abs(h[i]-h[i-1])
  b = calc_cost(i-2)+abs(h[i]-h[i-2])
  
  memo[i] = min(a,b)
  return(memo[i])

print(calc_cost(N-1))

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

using namespace std;

int main(){
	string s;
	cin>>s;
	int n=s.length();
	vector<pair<int,int>> same;
	char cur='R';int score=1;
	for(int i=1;i<n;i++){
		if(s[i]!=cur){
			same.push_back({score,i-1});
			score=1;
			cur=s[i];
		}
		else{
			score++;
		}
	}
	same.push_back({score,n-1});
	int j=0;
	for(int i=0;i<n;i++){
		//printf("%d %d\n",i,j);
		if(i==same[j].second){
			int cur=same[j].first+same[j+1].first;
			if(cur%2){
				if(same[j].first%2){
					printf("%d %d ",cur/2+1,cur/2);
				}
				else{
					printf("%d %d ",cur/2,cur/2+1);
				}
			}
			else{
				printf("%d %d ",cur/2,cur/2);
			}
			i++;j+=2;
		}
		else{
			printf("0 ");
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 1528
#!/usr/bin/env python3
import sys


def solve(a, b, c, d):
    x = c -a
    y = d -b
    return print(f"{c-y} {d + x} {a - y} {b + x}")


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    a, b, c, d = map(int, input().split())
    solve(a, b, c, d)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61876
#include <bits/stdc++.h>
#define rep(k,i,n) for(long long i=k;i<n;++i)
typedef long long ll;
using namespace std;
int main(void){
    // Your code here!
    ll N;
    cin>>N;
    ll a[3][N];
    rep(0,i,N)rep(0,j,3)cin>>a[j][i];
    rep(1,i,N){
        a[0][i]+=max(a[1][i-1],a[2][i-1]);
        a[1][i]+=max(a[0][i-1],a[2][i-1]);
        a[2][i]+=max(a[0][i-1],a[1][i-1]);
    }
    cout<<max(a[0][N-1],max(a[1][N-1],a[2][N-1]))<<endl;
}


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw_2(62,1);


int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,61) pw_2[i]=-2*pw_2[i-1];}
    
    ll N,K; cin>>N>>K;
    vector<ll> P(N);
    rep(i,N) cin>>P[i];
    ll tmp=0,M=0;
    rep(i,K) tmp+=P[i]; //0~K-1
    chmax(M,tmp);
    FOR(i,K,N){
        tmp-=P[i-K];
        tmp+=P[i];
        chmax(M,tmp);
    }
    printf("%.13f\n",(M+K)/2.0);
    
}



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

#define REP(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define REPS(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define RREP(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define RREPS(i, n) for (int i = ((int)(n)); i > 0; i--)
#define IREP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define IREPS(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVISORT(v) sort(v.begin(), v.end(), greater<int>());
#define ALL(v) v.begin(), v.end()
#define MP(n, m) make_pair(n, m);

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using ll = long long;
using ul = unsigned long;

typedef long long ll;

template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

const int mod=1e9+7;

void printv(VI& v){
  REP(i,v.size()) cout << v[i] << " ";
  cout << endl;
}

int vtotal(VI& v){
  int total=0;
  REP(i,v.size()) total+=v[i];
  return total;
}

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

	ll s;
	cin>>s;
  int lim=1e9;
  int y=(s/lim)+1;
  int x=lim-s%lim;

  if(s!=1e18) cout << 0 << " " << 0 << " " << lim << " " << 1 << " " << x << " " << y << endl;
  else cout << 0 << " " << 0 << " " << lim << " " << 0 << " " << lim << " " << lim << endl; // s==1e18の例外処理

  return 0;
}

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

signed main() {
	int n, m; cin >> n >> m;
	vector<bool> bs(n);
	rep(i, n) {
		int x; cin >> x;
		bs[i] = x;
	}
	vector<bool> a(n), b(n);
	int tb = 0;
	int idx = 0;
	rep(i, m) {
		int p; cin >> p;
		rep(j, p) {
			a[idx] = tb;
			b[idx] = !tb;
			idx++;
		}
		tb = !tb;
	}
	int mb = 1 << 15;
	
	using P = pair<vector<bool>, int>;
	unordered_map<vector<bool>, int> visited;
	queue<P> que;
	que.push(P(bs, 0));
	visited[bs] = 0;
	int ans = -1;
	
	while (!que.empty()) {
		P p = que.front(); que.pop();
		auto& pb = p.first;
		auto& pc = p.second;
		if (pb == a || pb == b) {
			ans = pc;
			break;
		}
		rep(i, n - 1) {
			vector<bool> next = pb;
			swap(next[i], next[i + 1]);
			int nc = pc + 1;
			if (visited.count(next)) continue;
			visited[next] = nc;
			que.emplace(next, nc);
		}
	}
	cout << ans << endl;
	
	
}

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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...)
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update

using namespace __gnu_pbds;

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

int main()
{
	#ifdef DGC
		//freopen("a.txt", "r", stdin);
		//freopen("b.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;
	vector<pair<int, int>> a(n);
	for (auto &i : a) cin >> i.F >> i.S;

	sort(a.begin(), a.end());
	ordered_set<int> lx, rx;
	for (int i = 0; i < n; ++i)
		rx.insert(a[i].S);

	auto up = [&](int y, ordered_set<int> &o)
	{
		return o.size() - o.order_of_key(y);
	};

	auto down = [&](int y, ordered_set<int> &o)
	{
		return o.order_of_key(y);
	};

	const ll mod = 998244353;
	vector<ll> p(n+1);
	p[0] = 1;
	for (int i = 1; i <= n; ++i)
		p[i] = p[i-1] * 2 % mod;

	for (auto &i : p)
	{
		i += mod-1;
		i %= mod;
	}

	ll ans = 0;
	for (int i = 0; i < n; ++i)
	{
		rx.erase(a[i].S);

		ans += p[n];

		ans -= p[lx.size()];
		ans -= p[rx.size()];
		ans -= p[up(a[i].S, lx) + up(a[i].S, rx)];
		ans -= p[down(a[i].S, lx) + down(a[i].S, rx)];
		ans += p[up(a[i].S, lx)];
		ans += p[up(a[i].S, rx)];
		ans += p[down(a[i].S, lx)];
		ans += p[down(a[i].S, rx)];
		ans %= mod;

		lx.insert(a[i].S);
	}

	ans += mod;
	ans %= mod;
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 14208
import java.util.*;
public class Main {

    public static void main(String[] args) {
        //try {
          //  File inputFile = new File("src/ITP1/dataSetPTC.txt");
            Scanner scan = new Scanner(System.in);
            String caseStr = "Case ";
            String colonStr = ": ";
            int line = 1;
            while (scan.hasNext()) {
                int inputNum = scan.nextInt();
                if(inputNum == 0) {
                    break;
                }
                System.out.println(caseStr + line + colonStr + inputNum);
                line ++;
            }
        //} catch (FileNotFoundException e) {
        //    e.printStackTrace();
       // }
    }
}

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

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

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
 int main()
{lli i,j;
vector<lli>in(5);
for(i=0;i<5;i++){
	cin >> in[i];
	if(in[i]==0)j=i;
}
cout << j+1 << '\n';
return 0;}

Measured memory_bytes: 3616
#include<stdio.h>
int main()
{
    int a,b,c,temp;
    scanf("%d%d%d",&a,&b,&c);
    if(a>b)
    {
        temp=b;
        b=a;
        a=temp;
    }
    if(a>c)
    {
        temp=c;
        c=a;
        a=temp;
    }
    if(b>c)
    {
        temp=b;
        b=c;
        c=temp;
    }

    printf("%d %d %d\n",a,b,c);

  return 0;

}



Measured memory_bytes: 2040
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


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

  std::cout << std::fixed << std::setprecision(6);

  int N, c = 0;

  std::cin >> N;

  for (int i = 1; i <= N; i ++)
    c += i;

  std::cout << c << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REP(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define REP1(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Int = long long;

//INT_MAX = 2147483647;
//LLONG_MAX = 9223372036854775807;
//ULLONG_MAX = 18446744073709551615;
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    bool ta=false,ao=false;
    while(1){
        c-=b;
        if(c<=0){
            ta = true;
            break;
        }
        a-=d;
        if(a<=0){
            ao = true;
            break;
        }
    }

    if(ta) cout << "Yes";
    if(ao) cout << "No";

    
    
    return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  string tt = t.substr(0, t.size() - 1);
  if (s == tt) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
typedef long long ll;
typedef unsigned int uint;
using namespace std;
bool visited[100005];
int n, m, a, b;
vector <int> vertex[100005], path, path2;

void dfs(int x) {
    visited[x] = true;
    path.push_back(x);
    for (int i = 0; i < vertex[x].size(); i++) {
        if (!visited[vertex[x][i]]) {
            dfs(vertex[x][i]);
            return;
        }
    }
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;

    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        vertex[a].push_back(b);
        vertex[b].push_back(a);
    }

    dfs(1);
    swap(path, path2);
    dfs(1);

    cout << path2.size() + path.size() - 1 << "\n";
    for (int i = path.size() - 1; i > 0; i--) {
        cout << path[i] << " ";
    }
    for (int i = 0; i < path2.size(); i++) {
        cout << path2[i] << " ";
    }

    return 0;
}

Measured memory_bytes: 9720
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


class UnionFind:
    def __init__(self, n: int):
        self.nodes = n
        self.parents = [-1] * n
        self.rank = [0] * n

    # retrun the root of element x
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # unite the group include element x and group include element y
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parents[y] += self.parents[x]
            self.parents[x] = y
        else:
            self.parents[x] += self.parents[y]
            self.parents[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # get size of the gourp which element x belongs
    def get_size(self, x):
        return -self.parents[self.find(x)]

    # check if element x and element y is same group
    def same(self, x, y):
        return self.find(x) == self.find(y)


def main():
    N, M = [int(i) for i in input().strip().split()]
    links = [None] * M
    for i in range(M):
        links[i] = [int(i)-1 for i in input().strip().split()]

    u = UnionFind(N)
    ans = list()
    x = N * (N - 1) // 2

    for a, b in links[::-1]:
        ans.append(x)
        if not u.same(a, b):
            x -= u.get_size(a) * u.get_size(b)
        u.unite(a, b)
    return ans


if __name__ == "__main__":
    for ans in main()[::-1]:
        print(ans)


Measured memory_bytes: 96644
#include <bits/stdc++.h>
using namespace std;
const int MAX=100005;

int dp[MAX][3];
int main(){
    int N;
    cin >> N;
    int i,j;
    int a[3];
    for(i=0;i<N;i++){
        cin >> a[0] >> a[1] >> a[2];
        if(i==0)for(j=0;j<3;j++)dp[i][j]=a[j];
        else{
            dp[i][0]=a[0]+max(dp[i-1][1],dp[i-1][2]);
            dp[i][1]=a[1]+max(dp[i-1][0],dp[i-1][2]);
            dp[i][2]=a[2]+max(dp[i-1][0],dp[i-1][1]);
            }}
    int ans=0;
    for(j=0;j<3;j++)if(ans<dp[N-1][j])ans=dp[N-1][j];
    cout << ans << endl;
}

Measured memory_bytes: 1408
N = int(input())
P = list(map(int, input().split()))
c = 0
for i in range(N):
    if P[i] == i+1:
        if i != N - 1:
            t = P[i]
            P[i] = P[i+1]
            P[i+1] = t
            c += 1
        else:
            t = P[i]
            P[i] = P[i-1]
            P[i-1] = t
            c += 1
print(c)

Measured memory_bytes: 83836
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
ll pow[7] = {1, 10, 100, 1000, 10000, 100000, 1000000};

int len(int n){
    int ans = 0;
    while(n != 0){
        ans++;
        n /= 10;
    }
    return ans;
}

int inv(int n){
    int ans = 0;
    while(n != 0){
        ans *= 10;
        ans += n%10;
        n /= 10;
    }
    return ans;
}

int inv_max(int n){
    int ans = 0;
    int k = len(n);
    ans += pow[k-1]*(n%10);
    for(int i = 1; i < k-1; i++){
        ans += pow[i]*9;
    }
    while(n >= 10){
        n /= 10;
    }
    if(k > 1)ans += n;
    return ans;
}

int inv_min(int n){
    int ans = 0;
    int k = len(n);
    ans += pow[k-1]*(n%10);
    while(n >= 10){
        n /= 10;
    }
    if(k > 1)ans += n;
    return ans;
}

ll cnt[10][10];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N;
    cin >> N;
    ll ans = 0;
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            if(i*10+j <= N) cnt[i][j]++;
            for(int k = 1; k < 10; k++){
                if(i+pow[k+1]*j > N) break;
                int base = i+pow[k+1]*j;
                int l = 0;
                int r = (pow[k]-1);
                if(base+r*10 <= N) {
                    cnt[i][j] += (pow[k]);
                }else{
                    while(r-l > 1){
                        int c = (l+r)/2;
                        if(base+c*10 <= N) l = c;
                        else r = c;
                    }
                    cnt[i][j] += (l+1);
                }
            }
        }
    }
    for(int i = 1; i <= 9; i++){
        if(i <= N) ans+=1;
    }
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            // cout << cnt[i][j] << ' ';
            ans += cnt[i][j]*cnt[j][i];
            if(i == j){
                if(i <= N){
                    ans += (2*cnt[i][j]);
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
typedef struct Dice{int t,s,e,w,n,b;}dice;
 
void koro(dice *d,char *h){
    dice dbuf;
    dbuf.t=d->t;dbuf.s=d->s;dbuf.e=d->e;dbuf.w=d->w;dbuf.n=d->n;dbuf.b=d->b;
    switch(*h){
        case 'S':
            d->t=dbuf.n;
            d->s=dbuf.t;
            d->e=dbuf.e;
            d->w=dbuf.w;
            d->n=dbuf.b;
            d->b=dbuf.s;
            break;
        case 'E':
            d->t=dbuf.w;
            d->s=dbuf.s;
            d->e=dbuf.t;
            d->w=dbuf.b;
            d->n=dbuf.n;
            d->b=dbuf.e;
            break;
        case 'W':
            d->t=dbuf.e;
            d->s=dbuf.s;
            d->e=dbuf.b;
            d->w=dbuf.t;
            d->n=dbuf.n;
            d->b=dbuf.w;
            break;
        case 'N':
            d->t=dbuf.s;
            d->s=dbuf.b;
            d->e=dbuf.e;
            d->w=dbuf.w;
            d->n=dbuf.t;
            d->b=dbuf.n;
            break;
    }
}
 
int main(void){
    dice di;
    int i,q,dice[7],target_top,target_front;
    char hoko[101]={NULL};
    for(i=0;i<6;i++)scanf("%d",&dice[i]);
    di.t=dice[0];di.s=dice[1];di.e=dice[2];di.w=dice[3];di.n=dice[4];di.b=dice[5];
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d %d",&target_top,&target_front);
		if	   (di.s==target_top) koro(&di,"N");
		else if(di.e==target_top) koro(&di,"W");
		else if(di.w==target_top) koro(&di,"E");
		else if(di.n==target_top) koro(&di,"S");
		else if(di.b==target_top){koro(&di,"S");koro(&di,"S");}

		if     (di.e==target_front){koro(&di,"W");koro(&di,"S");koro(&di,"E");}
		else if(di.w==target_front){koro(&di,"E");koro(&di,"S");koro(&di,"W");}
		else if(di.n==target_front){koro(&di,"S");koro(&di,"S");koro(&di,"E");koro(&di,"E");}
		
		printf("%d\n",di.e);
	}
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> nums(n);

    int max_num = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        nums[i] = a;
        max_num = max(max_num, a);
    }

    for (int i = 1; i <= max_num; i++) {
        bool flag = true;
        for (int j = 0; j < n; j++) {
            if (nums[j] % i != 0) {
                flag = false;
                break;
            }
        }
        if (flag)
            cout << i << endl;
    }
    return 0;
}


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

int main(){
  ll A,B;
  cin >> A >> B;
  for(ll i=1;true;i++){
    if((A*i)%B==0){
      cout << A*i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Train Ticket

            //4つの数字を取得
            var numbers = GetSourceNumbers().ToList();

            string formula = GetFormulaToBeSeven(numbers);
            Console.WriteLine(formula);
        }

        static IEnumerable<int> GetSourceNumbers()
        {
            string line = Console.ReadLine().TrimEnd();

            foreach(var c in line)
            {
                yield return int.Parse(c.ToString());
            }
        }

        static string GetFormulaToBeSeven(List<int> numbers)
        {
            var variations = new string[8] 
            {
                "+++", "++-", "+-+", "+--", "-++", "-+-", "--+", "---"
            };

            foreach(var s in variations)
            {
                int sum = numbers[0];

                for(int i = 0; i < 3; i++)
                {
                    if (s[i] == '+')
                    {
                        sum += numbers[i + 1];
                    }
                    else
                    {
                        sum -= numbers[i + 1];
                    }
                }

                if (sum == 7)
                {
                    string formula = "";

                    for(int i = 0; i < 3; i++)
                    {
                        formula += numbers[i] + s[i].ToString();
                    }

                    formula += numbers[3] + "=7";
                    return formula;
                }
            }

            return null;
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A[5];
    for(int i=0;i<3;i++){
        cin>>A[i];
    }
    sort(A,A+3);
    
    cout<<A[2]*10+A[1]+A[0]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<map>
#include<vector>
#include<iostream>
#include<algorithm> // sort,reverse,min,lower_bound
using namespace std;
#define df 0
#define INF 1000000000
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define chmin(a,b) if((a)>(b)) a=(b)
#define chmax(a,b) if((a)<(b)) a=(b)
#define ceil(a,b) (((a)+(b)-1)/(b))
typedef long int li;
template<typename T>
void print_item(T x) {cout << x;}

// vector 型
template<typename T>
void print(vector<T>& vec,string str=""){
  if(str!="") cout << str << ":";
  for(T x: vec) {print_item(x); cout << " ";}
  cout << endl;
}
// pair 型の print (map 含む)
template<typename F,typename S>
void print_item(pair<F,S> x) {
  printf("(");
  print_item(x.first);
  printf(",");
  print_item(x.second);
  printf(")");
}

// map 型
template<typename F,typename S>
void print(map<F,S>& vec,string str=""){
  if(str!="") cout << str << ":";
  for(auto x: vec) {print_item(x); cout << " ";}
  cout << endl;
}



int main(){
  if(df) printf("*debug mode*\n");
  int n,d,a; cin >>n >>d >>a;
  map<li,int> mp;
  rep(i,n){
    li x;int h; cin >>x >>h;
    h=ceil(h,a);
    mp[x]=h;
  }
  li s=0;
  for(auto& p:mp){
    p.second-=s;
    s+=p.second;
  }
  if(df)print(mp);
  s=0;li ans=0;
  for(auto& p:mp){
    s+=p.second;
    if(s<=0)continue;
    p.second-=s;
    ans+=s;
    auto itr=mp.lower_bound(p.first+d*2+1);
    if(itr!=mp.end()){
      itr->second+=s;
    }
    s=0;
    if(df)print(mp);
  }
  cout << ans;
}

/// confirm df==0 ///


Measured memory_bytes: 14848
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define int long long
using namespace std;

int x[300010],y[300010];
int h[1000000],w[1000000];

inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}

inline bool read(int& a){
    int s=0,w=1;
    char ch=getchar();
    if(ch==EOF){
		return false;
	}
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    a=s*w;
    return true;
}

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

inline void writeln(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
    puts("");
}

signed main(){
    int H,W,M;
    read(H),read(W),read(M);
    
    for(int i=1;i<=M;i++){
        x[i]=read();
        y[i]=read();
        h[x[i]]++;
        w[y[i]]++;
    }
    
    int a=0,b=0;
    int maxh=0,maxw=0;
    int maxv=0,maxx=0;
    
    for(int i=1;i<=H;i++)
        maxh=max(maxh,h[i]);
        
    for(int i=1;i<=H;i++)
        if(h[i]==maxh)
            a++;
            
    for(int i=1;i<=W;i++)
        maxw=max(maxw,w[i]);
        
    for(int i=1;i<=W;i++)
        if(w[i]==maxw)
            b++;
            
    maxv=a*b;
    
    for(int i=1;i<=M;i++)
        if(h[x[i]]==maxh and w[y[i]]==maxw)
            maxx++;
            
    if(maxv==maxx)
        writeln(maxw+maxh-1);
    else
        writeln(maxw+maxh);
        
    return 0;
}

Measured memory_bytes: 12976
#include <bits/stdc++.h>
#define LIM 1<<17
/// TONI BO$$ was here
/// #MLC

using namespace std;
char BUF[LIM];
int poz;

inline char getChar(){
    poz++;
    if(poz>=LIM){
    	fread(BUF,LIM,1,stdin);
    	poz=0;
    }
    return BUF[poz];
}

inline int getNr(){
    int r=0, semn=1;
    char ch=getChar();
    while(isdigit(ch)==0 && ch!='-') ch=getChar();
    if(ch=='-'){
        semn=-1;
        ch=getChar();
    }
    while(isdigit(ch)!=0){
        r=r*10+semn*(ch-'0');
        ch=getChar();
    }
    return r;
}

int main()
{
    int n,h,w,x,a,b;
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%d%d%d",&n,&h,&w);
    x=0;
    while(n--)
    {
        scanf("%d%d",&a,&b);
        if(a>=h && b>=w)
            x++;
    }
    printf("%d",x);

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
	public static void main(String arg[])
	{
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext())
		{
			double x = sc.nextDouble();
			double h = sc.nextDouble();
			double l=0;
			if(x==0 && h==0)
				return;

			double s1 = x*x;
			l=Math.sqrt(((x/2)*(x/2))+(h*h));
			double s2 = (x*l/2)*4;
			double ans = s1+s2;
			System.out.printf("%.6f", ans);
			System.out.println();
		}


	}

}

Measured memory_bytes: 12000
n,k = map(int,input().split())
ab = [tuple(map(int,input().split())) for _ in range(n)]
ab.sort(key = lambda x:x[0])
i = 0
j = 0
while i < k:
  i += ab[j][1]
  j += 1
  
print(ab[j-1][0])
    

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

#define MAX 100005
#define NIL -1

struct Node { int p, l, r; };

Node T[MAX];
int n, D[MAX];

void print(int u) {
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";
    
    if ( T[u].p == NIL ) cout << "root, ";
    else if ( T[u].l == NIL ) cout << "leaf, ";
    else cout << "internal node, ";
    
    cout << "[";
    
    for ( i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
        if (i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

// 再帰的に深さを求める
int rec(int u, int p) {
    D[u] = p;
    if ( T[u].r != NIL ) rec(T[u].r, p);
    if ( T[u].l != NIL ) rec(T[u].l, p + 1);

    return 0;
}

int main(void){
    int i, j, d, v, c, l, r;
    cin >> n;
    for ( i = 0; i < n; i++ ) T[i].p = T[i].l = T[i].r = NIL;
    
    for ( i = 0; i < n; i++) {
        cin >> v >> d;
        for ( j = 0; j < d; j++) {
            cin >> c;
            if ( j == 0 ) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    for ( i = 0; i < n; i++) {
        if (T[i].p == NIL) r = i;
    }

    rec(r, 0);
    
    for ( i = 0; i < n; i++) print(i);
    
    return 0;
}



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

int main(){
  int n; 
  cin >> n;
  vector<int> a(n);
  rep(i,n){
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  rep(i,n-1){
    if(a.at(i) == a.at(i+1)){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 1024
n = int(input())
a = list(map(int,input().split()))
prev = [-1 for _ in range(3)]
ans = 1
mod = 10**9+7
for i in a:
    ans*=prev.count(i-1)
    ans%=mod
    if ans==0:
        print(0)
        exit()
    for j in range(3):
        if prev[j]==i-1:
            prev[j] = i
            break
print(ans)

Measured memory_bytes: 14056
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long k = in.nextLong();

        Map<Integer, Long> m = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            int a = in.nextInt();
            int b = in.nextInt();
            m.putIfAbsent(a, 0L);
            m.put(a, m.get(a) + b);
        }

        for (int a : m.keySet()) {
            k -= m.get(a);
            if (k <= 0) {
                System.out.println(a);
                return;
            }
        }
    }
}


Measured memory_bytes: 89068
from math import sin, cos, radians

eps = 10**-5

def sim(rot):
    x, y = 0, 0
    nx, ny = 0, 1
    cnt = 0
    while True:
        x += nx
        y += ny
        # print(x, y, nx, ny)
        # if cnt >= 10:
            # break
        cnt += 1
        if -eps <= x <= eps and -eps <= y <= eps:
            break
        nx, ny = nx * cos(radians(rot)) -  ny * sin(radians(rot)), ny * cos(radians(rot)) + nx * sin(radians(rot))
    return cnt

# print(sim(90))
# exit(0)

n = int(input())
print(sim(n))

# for i in range(1, 180):
#     print(i, sim(i))

Measured memory_bytes: 62596
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
main(){
  int n,m; cin>>n>>m;
  int count(0);
  rep(i,n){
    string s; cin>>s;
    rep(j,m){
      if(s[j]=='#'){
        count++;
      }
    }
  }
  if(count==n+m-1){
    cout<<"Possible";
  }else{
    cout<<"Impossible";
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair <int, int>;
const double PI = acos(-1);
const ll MOD = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<string> s(N);

  ll cnt = 0;

  rep(i, N) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
    //cout << s[i] << endl;
  }

  map<string, int> mp;

  rep(i, N) mp[s[i]]++;

  for(auto p : mp){
    ll n = p.second;
    cnt += n * (n-1) / 2;
  }
  cout << cnt << endl;
}


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

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

    long long ans = 0;
    for (int i = 1; i < N + 1; i++) {
        if (i % 3 == 0 || i % 5 == 0) continue;
        ans += i;
    }

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

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
map <pair<ll, ll>, int> maps;

ll quick_pow(ll a, ll n){
    ll ans = 1;
    while(n){
        if(n & 1) ans = (ans * a)%mod;
        a = (a * a)%mod;
        n >>= 1;
    }
    return ans;
}

ll gcd(ll a, ll b){
    return !b?a:gcd(b, a%b);
}

int main(){
    int n; cin >> n;
    int count0 = 0;
    for(int i = 0; i < n; i++){
        ll a, b; cin >> a >> b;
        ll c = gcd(a, b);
        if(!c){ count0++; continue;}  // compute the number of (0, 0)
        a /= c, b /= c;
        if(a < 0) a = -a, b = -b; //store pair(a, b)
        maps[make_pair(a, b)]++;
    }
    ll ans = 1;
    for(map <pair<ll, ll>, int>::iterator it = maps.begin(); it != maps.end(); it++){  //iterator for maps
        if(it->second == 0) continue;

        ll a = (it->first).first, b = (it->first).second;
        ll d = quick_pow(2, it->second);
        b = -b;
        if(b < 0) a = -a, b = -b;
        if(maps.count(make_pair(b, a))){
            d = (d + quick_pow(2, maps[make_pair(b, a)]) - 1) % mod;
            maps[make_pair(b, a)] = 0;
        }
        ans = ans * d % mod;
    }
    ans = (ans - 1 + count0 + mod) % mod; // subtract null
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 16032
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll n,m,c,b[30],a[30][30],k,ans;
  ans=0;
  cin >> n >> m >> c;
  k=0;
  rep(i,m)cin >> b[i];
  rep(i,n)rep(j,m)cin >> a[i][j];
  rep(i,n){
    rep(j,m){
      k+=a[i][j]*b[j];
    }
    if(k+c>0)ans++;
    k=0;
  }
  printf("%lld",ans);
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <math.h>
 
#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
//typedef pair<int,int> P;
 
bool P[101];
int d[101][101];
int res[101];
 
int main(){
	int N,M,L,K,A,H,a,x,y,t;
	int v[150];
	while(1){
		cin>>N>>M>>L>>K>>A>>H;
		if(N+M+L+K+A+H==0)break;
		memset(P,false,sizeof(P));
		REP(i,101)REP(j,101)d[i][j]=1e7;
		REP(i,L)cin>>v[i];
		v[L]=A;v[L+1]=H;
		REP(i,K){cin>>x>>y>>t;d[x][y]=d[y][x]=t;}
		REP(i,N)d[i][i]=0;
		REP(k,N)REP(i,N)REP(j,N)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		//REP(i,N){REP(j,N)cout<<d[i][j]<<" ";cout<<endl;}
		REP(i,L+2)REP(j,L+2)if(d[v[i]][v[j]]>M)d[v[i]][v[j]]=1e7;
		REP(k,L+2)REP(i,L+2)REP(j,L+2)d[v[i]][v[j]]=min(d[v[i]][v[j]],d[v[i]][v[k]]+d[v[k]][v[j]]);
		//REP(i,N){REP(j,N)cout<<d[i][j]<<" ";cout<<endl;}
		if(d[A][H]==1e7)cout<<"Help!"<<endl;
		else cout<<d[A][H]+max(0,d[A][H]-M)<<endl;
	}
}


Measured memory_bytes: 3160
#include<cstdio>
#include<vector>
#include<numeric>

using namespace std;

int main()
{
	int l[10],v[2];
	while(~scanf("%d",l)){
		for(int i=1;i<10;i++)	scanf(",%d",l+i);
		scanf(",%d,%d",v,v+1);
		int len=accumulate(l,l+10,0);
		vector<int> rail(len);
		for(int i=0,cnt=0;i<10;i++){
			for(int j=0;j<l[i];j++,cnt++){
				rail[cnt]=i+1;
			}
		}
		double x=1.0*v[0]/(v[0]+v[1])*len;
		if(-1e-9<(x-(int)x) && (x-(int)x)<1e-9)	x-=0.1;
		printf("%d\n",rail[(int)x]);
	}
	return 0;
}

Measured memory_bytes: 0
/*
_________________________
|   LIVE FREE OR DIE     |
|       327 2153         |
|          New           |
|_______HAMPSHIRE________|

*/
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define MAX 20
#define int long long
#define MOD 998244353

int n;
vector<vector<int> > g;
vector<int> ans,p,val;
multiset<int> s;
void dfs(int node,int parent)
{
	s.insert(val[node]);
	auto it = s.lower_bound(val[node]);
	it++;
	if(it!=s.end())
	{
		p[node]=*it;
		s.erase(it);
	}
	ans[node]=s.size();
	for(auto i:g[node])
	{
		if(i!=parent)
			dfs(i,node);
	}
	s.erase(s.lower_bound(val[node]));
	if(p[node]!=-1)
		s.insert(p[node]);
}
int32_t main()
{
	IOS
	cin>>n;
	val.resize(n+1);
	for(int i=1;i<=n;i++)
		cin>>val[i];
	g.resize(n+1,vector<int>());
	ans.resize(n+1);
	p.resize(n+1);
	for(int i=0;i<=n;i++)
		p[i]=-1;
	for(int i=0;i<n-1;i++)
	{
		int x,y;cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(1,-1);
	for(int i=1;i<=n;i++)
		cout<<ans[i]<<endl;
	return 0;
}

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

using namespace std;

int INF=1e9;

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

    long long a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;

    long long ans=a*x+b*y;

    if(x>=y){
        ans=min(ans,c*2*y+a*(x-y));
        ans=min(ans,c*2*x);
    }
    else{
        ans=min(ans,c*2*x+b*(y-x));
        ans=min(ans,c*2*y);
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include <algorithm>
#include <queue>
#include <climits>

bool sort_pair( std::pair< int, int > origin, std::pair< int, int > another )
{
    return origin.first < another.first;
}

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

    int c = b / 10;
    int d = b % 10;
    int count = 0;

    for( int i = 4; i <= a; i++ )
    {
        for( int r = 2; r <= b; r++ )
        {
            int c = r / 10;
            int d = r % 10;

            if( c > 1 &&
                d > 1 &&
                i == c * d )
            {
                count+=1;
            }
        }
    }

    std::cout<< count;

}


Measured memory_bytes: 256
#00:27
h,w = map(int,input().split())
raw = []
for _ in range(h):
  raw.append(input())
ver = [[] for _ in range(h)]
hrz = [[] for _ in range(h)]
for x in range(h):
  st = 0
  for y in range(w):
    if raw[x][y] == '#':
      for k in range(st,y):
        ver[x].append(y-st)
      ver[x].append(0)
      st = y + 1
  for k in range(st,w):
    ver[x].append(w-st)
#print(ver)
for y in range(w):
  st = 0
  for x in range(h):
    if raw[x][y] == '#':
      for k in range(st,x):
        hrz[k].append(x-st)
      hrz[x].append(0)
      st = x + 1
  for k in range(st,h):
    hrz[k].append(h-st)
#print(hrz)
ans = 0
for x in range(h):
  for y in range(w):
    ans = max(ans,ver[x][y]+hrz[x][y]-1)
print(ans)

Measured memory_bytes: 226052
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  rep(i, n){
    char s;
    cin >> s;
    if(s == 'Y'){
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
}

Measured memory_bytes: 256
/*
@author: sharrad99
*/
#include<bits/stdc++.h>
using namespace std;
int main(){

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

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

	int n = s.length(), m = t.length();

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

	string lcs;
	int i = n, j = m;
	while(i > 0 and j > 0) {
		if(s[i - 1] == t[j - 1]) {
			lcs += s[i - 1];
			i--, j--;
		}
		else {
			if(dp[i - 1][j] >= dp[i][j - 1]) {
				i--;
			}
			else {
				j--;
			}
		}
	}

	reverse(lcs.begin(), lcs.end());
	cout << lcs << '\n';
}

Measured memory_bytes: 35584
#include <iostream>
#include <algorithm>
int main() {
	int n, x, num;
	while (std::cin >> n >> x && (n != 0 || x != 0)) {
		n = std::min(n, x);
		num = 0;
		for (int i = 1; i <= n - 2; ++i) {
			for (int j = i + 1 ; j <= n - 1; ++j) {
				int k = x - i - j;
				if (j < k && k <= n) {
					++num;
				}
			}
		}
		std::cout << num << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3000