akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>

int n, sum[101][101];

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            int tmp;
            scanf("%d", &tmp);
            sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + tmp;
        }
    }


    int s, ans = sum[1][1];
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int k = i; k <= n; k++){
                for(int l = j; l <= n; l++){
                    s = sum[k][l] - sum[k][j - 1] - sum[i - 1][l] + sum[i - 1][j - 1];
                    if(s > ans) ans = s;
                }
            }
        }
    }

    printf("%d\n", ans);

    return 0;
}

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

#define lli long long int
#define pb push_back
#define f first
#define sec second

lli dp[100002];

main()
{
    lli n,i,a,t,j,k,b,c,x,y;

    cin>>n>>k;
    lli arr[n];

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

    dp[0] = 0;
    for(i=1;i<=k;i++)
    {
        dp[i] = 0;
        for(j=0;j<n;j++)
        {
            if(i>=arr[j])
            {
                if(dp[i-arr[j]] == 0)
                {
                    dp[i] = 1;
                    break;
                }
            }
        }
    }

    if(dp[k] == 1)
    {
        cout<<"First";
    }
    else
    {
        cout<<"Second";
    }
}


Measured memory_bytes: 1024
#include<iostream>

#include<cmath>
#include<string>
#include <algorithm> 

using namespace std;

# define p(s) cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) cout << (j ? "Yes" : "No") << endl;

string lpad(string l,int s,int n){
    string temp = to_string(n);
    string res = "";
    int loop = s - temp.size();
    while(loop--) res+=l;

    return res+temp;
}

int main()
{
    int a[4];
    cin >> a[0] >> a[1] >> a[2] ;

    std::sort(a,a+3);

    p(abs(a[1]-a[0])+abs(a[2]-a[1]))
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int ans[N],arr[N],n,m; 
int Find(int x)
{
    if(x == arr[x]) return x;
    return arr[x] = Find(arr[x]);
}
int main()
{	int Max=0;
    cin >> n >> m;
    for(int i = 1;i <= n;i++) arr[i] = i;
    while(m--)
    {
        int a,b;
        cin >> a >> b;
        if(a > b) swap(a,b);//确保单向性 
        if(Find(a) != Find(b))
            arr[Find(a)] = arr[Find(b)];
    }
    for(int i = 1;i <= n;i++)
    {
        int x = Find(arr[i]);
        ans[x]++;
        Max = max(Max,ans[x]);
    }
    cout << Max << endl;
    return 0;
}

Measured memory_bytes: 10472
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
//////////////////////////////////////////////////
int main(){
    int N; SCD(N);
    vector<int> a;
    vector<int> U;	
    int count = 1;

    VSCD(a,N);
    
    REP(i,a.size()-1){
        if (a[i] == a[i+1]){
            count++;
        }else{
            U.PB(count);
            count = 1;
        }
    }
    U.PB(count);
    int ans = 0;
    
    REP(i,U.size()){
        if (U[i] == 2) ans++;
        else ans += U[i]/2;
    }

    PRINTD(ans);

}

Measured memory_bytes: 256
//AnkitCode99 here....
//every ups and downs matter!

#include<bits/stdc++.h>
#define endl "\n"
#define Ryuga ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr)
typedef long long int ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)

using namespace std;

const ll sz=1e5+5;
const ll szz=1e6+6;
const ll mod=1e9+7;

int main()
{
    Ryuga;

   

    clock_t startTime=clock();

    ll k;
    string s;
    cin>>k>>s;
    if((ll)s.length()<=k)
    {
        cout<<s;
    }
    else
    {
        cout<<s.substr(0,k)+"...";
    }

    cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;

}//Goodbye...

Measured memory_bytes: 3792
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, K;
    cin >> N >> K;
    int64_t ans = 1;
    for (int i = 0; i < N; i++) {
        if (i == 0) ans *= K;
        else ans *= K - 1;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var N = parseInt(tmp[0], 10);
	var A = parseInt(tmp[1], 10);
	var B = parseInt(tmp[2], 10);

  var aSum = N*A;
  if(aSum < B) console.log('%d',aSum);
  else console.log('%d',B);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
s = input()
one = s.count('1')
zero = s.count('0')
print(one * 2 if one < zero else zero*2)


Measured memory_bytes: 10388
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		//new AOJ0578().run();
		new Main().run();
	}
	void run(){
		Scanner sc=new Scanner(System.in);
		
		while(sc.hasNext()){
			int n=sc.nextInt();
			int count=0;
			char name[]=sc.next().toCharArray();
			char old[][]=new char[n][];
			//いい名前が思い浮かばなかった。
			//temp[i]はつくりたい看板のi文字目がoldの何文字目にあったかを入れておく.
			int temp[]=new int[name.length];
			for(int i=0; i<n; i++){
				old[i]=sc.next().toCharArray();
			}
			
			for(int i=0; i<n; i++){
				for(int j=0; j<old[i].length; j++){
					if(name[0]==old[i][j]){
						//なんか関数を呼ぶ
						if(signBord(name, old[i], j, 0, temp)){
							//System.out.println(i+" "+String.valueOf(old[i]));
							count++;
							break;
						}
					}
				}
			}
			System.out.println(count);
		}
	}
	
	boolean signBord(char name[],char old[],int k,int d, int temp[]){
		temp[d]=k;
		if(name.length-1 <= d){
			for(int i=0; i+2<name.length; i++){
				if(temp[i+1]-temp[i] != temp[i+2]-temp[i+1]){
						return false;
				}
			}
			return true;
		}
		
		boolean f;
		
		for(int j=k+1; j<old.length; j++){
			if(name[d+1]==old[j]){
				if(signBord(name, old, j, d+1, temp)){
					return true;
				}
			}
		}
		return false;
	}

}

Measured memory_bytes: 21772
#include<stdio.h>

int main(){
	int i, a = 0, b = 0, c = 0, amari = 0, cnt = 0;
	scanf("%d %d %d", &a, &b, &c);
	for(i = 1; i <= 10000; i++){
		if(a <= i && i <= b){
			if( (amari = c % i) == 0)  cnt++;
		}
	}
	printf("%d\n", cnt);
	return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int N = 1e5;
VI e[N];
int cmp[N];

void dfs(int now, int c){
    cmp[now] = c;
    for (int next : e[now]){
        if (cmp[next] == c) continue;
        dfs(next, c);
    }
}

int main() {
    ll n, m;
    cin >> n >> m;
    REP(i,m){
        int u, v;
        scanf("%d %d", &u, &v);
        u--;
        v--;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    dfs(0, 1);
    dfs(1, 2);

    ll one = 0, two = 0;
    REP(i,n){
        if (cmp[i] == 1) one++;
        if (cmp[i] == 2) two++;
    }
    ll emp = n - one - two;

    cout << max((one + emp) * (one + emp - 1) / 2 + two * (two - 1) / 2, one * (one - 1) / 2 + (two + emp) * (two + emp - 1) / 2) - m << endl;

    return 0;
}




Measured memory_bytes: 9216
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
// #include<assert.h>
#include<random>
using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{ 
  int N; cin>>N;
  vector<int> vec (N,0);
  for (int i = 0; i < N; i++)
  {
     cin>>vec[i];
  }
  vector<int> data;
  data.push_back(-1*vec[0]);
  for (int i = 1; i < N; i++)
  {
    int X = -1*vec[i];
    auto itr = upper_bound(ALL(data),X);
    if(itr == data.end())
    {
      data.push_back(X);
    }
    else
    {
      *itr =X;
    }

  }
  cout<<data.size()<<endl;
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 5016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

int main() {
    while (true) {
        int n, w, d;
        cin >> n >> w >> d;
        if (n == 0 && w == 0 && d == 0) break;

        vector<int> p(n), s(n);
        REP(i, n) {cin >> p[i] >> s[i]; p[i]--;}

        list<pair<int, int>> cake; // (幅, 奥行き)
        cake.push_back(MP(w, d));

        // for (auto itr = cake.begin(); itr != cake.end(); itr++) {
        //     printf("(%d, %d), ", (*itr).first, (*itr).second);
        // }
        // printf("\n");

        REP(i, n) {
            auto itr = cake.begin();
            REP(j, p[i]) itr++;
            pair<int, int> cake2cut = *itr;
            cake.erase(itr);

            int w2cut = cake2cut.first;
            int d2cut = cake2cut.second;
            int wd2cut = w2cut + d2cut;
            int ss = s[i] % wd2cut;

            // 縦に切る
            if (ss < w2cut) {
                int new_w1 = min(ss, w2cut - ss);
                int new_w2 = max(ss, w2cut - ss);
                cake.push_back(MP(new_w1, d2cut));
                cake.push_back(MP(new_w2, d2cut));
            }

            // 横に切る
            else {
                int new_d1 = min(ss - w2cut, wd2cut - ss);
                int new_d2 = max(ss - w2cut, wd2cut - ss);
                cake.push_back(MP(w2cut, new_d1));
                cake.push_back(MP(w2cut, new_d2));
            }

            // for (auto itr = cake.begin(); itr != cake.end(); itr++) {
            //     printf("(%d, %d), ", (*itr).first, (*itr).second);
            // }
            // printf("\n");

            // vector<int> cake_space;
            // for (auto itr = cake.begin(); itr != cake.end(); itr++) {
            //     cake_space.PB((*itr).first * (*itr).second);
            // }
            // sort(cake_space.begin(), cake_space.end());

            // REP(i, cake_space.size()) {
            //     if (i > 0) printf(" ");
            //     printf("%d", cake_space[i]);
            // }
            // printf("\n");
        }

        vector<int> cake_space;
        for (auto itr = cake.begin(); itr != cake.end(); itr++) {
            cake_space.PB((*itr).first * (*itr).second);
        }
        sort(cake_space.begin(), cake_space.end());

        REP(i, cake_space.size()) {
            if (i > 0) printf(" ");
            printf("%d", cake_space[i]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3180
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cout << (#x) << ": " << (x) << endl
#define DEBUG_VEC(v)          \
  cerr << #v << ": ";         \
  REP(__i, (v).size())        \
  cerr << ((v)[__i]) << ", "; \
  cerr << endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
  ios::sync_with_stdio(false);
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vl a(x);
  vl b(y);
  vl c(z);
  REP(i, x) cin >> a[i];
  REP(i, y) cin >> b[i];
  REP(i, z) cin >> c[i];
  sort(a.begin(), a.end(), greater<ll>());
  sort(b.begin(), b.end(), greater<ll>());
  sort(c.begin(), c.end(), greater<ll>());
  priority_queue<tuple<ll, ll, ll, ll>> q;
  set<tuple<ll, ll, ll>> seen;

  q.push(make_tuple(a[0] + b[0] + c[0], 0, 0, 0));
  seen.insert(make_tuple(0, 0, 0));

  ll ans = 0LL;
  REP(p, k) {
    ll v, i, j, k;
    tie(v, i, j, k) = q.top();
    cout << v << endl;
    q.pop();
    tuple<ll, ll, ll> t;

    t = make_tuple(i + 1, j, k);
    if (seen.find(t) == seen.end() and i + 1 < x) {
      seen.insert(t);
      q.push(make_tuple(a[i + 1] + b[j] + c[k], i + 1, j, k));
    }

    t = make_tuple(i, j + 1, k);
    if (seen.find(t) == seen.end() and j + 1 < y) {
      seen.insert(t);
      q.push(make_tuple(a[i] + b[j + 1] + c[k], i, j + 1, k));
    }

    t = make_tuple(i, j, k + 1);
    if (seen.find(t) == seen.end() and k + 1 < z) {
      seen.insert(t);
      q.push(make_tuple(a[i] + b[j] + c[k + 1], i, j, k + 1));
    }
  }

  return 0;
}


Measured memory_bytes: 1024
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string str;cin>>str;
	int i,n=str.size(),C=0;
	for(i=1;i<n;i++){
		if(str[i]=='C'&&2<=i&&i<n-1){C++;}
		else if('A'<=str[i]&&str[i]<='Z'){C=-999;}
	}
	
	cout<<((str[0]=='A'&&C==1)?"AC":"WA")<<endl;
	return 0;
}


Measured memory_bytes: 256
import Control.Monad
main = do
  s <- getLine
  n <- readLn :: IO Int
  cmds <- replicateM n $ (return . words) =<< getLine
  foldM f1 s cmds

f1 s [cmd,a1,a2] | cmd == "print" = do
                          putStrLn $ drop (read a1) $ take (1 + read a2) s
                          return s
f1 s [cmd,a1,a2] | cmd == "reverse" = return $ (take (read a1) s) ++ (reverse $ drop (read a1) $ take (1 + read a2) s) ++ (drop (1 + read a2) s)
f1 s [cmd,a1,a2,p] = do return $ (take (read a1) s) ++ p ++ (drop (1 + read a2) s)


Measured memory_bytes: 6084
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int h, a;
    cin >> h >> a;
    OUT((h+a-1)/a)

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <vector>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define vec vector<int>
#define vecll vector<ll>
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
struct UnionFind{
    vec par,size;
    UnionFind(int n):par(n),size(n){
        rep(i,n){
            par[i]=i;
            size[i]=1;
        }
    }
    int root(int x){
        if(par[x]==x)return x;
        return root(par[x]);
    }
    void unite(int x, int y){
        int rx=root(x);
        int ry=root(y);
        if(rx==ry)return;
        if(size[rx]<size[ry]){
	        par[rx]=ry;
    	    size[ry]+=size[rx];
        }else{
	        par[ry]=rx;
    	    size[rx]+=size[ry];
        }
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
};
int main(){
    ll n=lin();
    int m=in();
    UnionFind tree(n);
    vecll a(m),b(m),ans(m);
    ans[m-1]=0;
    rep(i,m){
        a[i]=in()-1;
        b[i]=in()-1;
    }
    rep3(i,m-2,0){
        if(!tree.same(a[i+1],b[i+1])){
            ans[i]=ans[i+1]+tree.size[tree.root(a[i+1])]*tree.size[tree.root(b[i+1])];
            tree.unite(a[i+1],b[i+1]);
        }else ans[i]=ans[i+1];
    }
    ll k=n*(n-1)/2;
    rep(i,m)cout<<k-ans[i]<<endl;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define DEBUG2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << "\n"
#define DEBUG3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair<int, int>
#define ld long double
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  int diff = B - A;
  bool ok = false;
  REPS(i, N - 1) {
    int revI = N - 1 - i;
    int minV = C * i - D * revI;
    int maxV = D * i - C * revI;
    if (minV <= diff && diff <= maxV) {
      ok = true;
      break;
    }
  }
  print(ok ? "YES" : "NO");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>

const int MAX_N = 200050;
int N;
std::string S;

int init[MAX_N];
int AC_WHITE[MAX_N], AC_BLACK[MAX_N];
 
int main(int argc, char **argv) {
    std::cin >> N;
    std::cin >> S;

    AC_WHITE[0] = 0;
    AC_BLACK[0] = 0;

    for (int i = 1; i <= N; i++) {
        if (S[i-1] == '.') {
            init[i] = 0;
            AC_WHITE[i] = AC_WHITE[i-1] + 1;
            AC_BLACK[i] = AC_BLACK[i-1];
        } else {
            init[i] = 1;
            AC_WHITE[i] = AC_WHITE[i-1];
            AC_BLACK[i] = AC_BLACK[i-1] + 1;
        }
    }

    int ret = MAX_N;
    for (int bb = 1; bb <= N + 1; bb++) {
        //std::cout << bb << " " << AC_BLACK[bb-1] << " " << AC_WHITE[N] << " " << AC_WHITE[bb-1] << std::endl;
        ret = std::min(ret, AC_BLACK[bb-1] + AC_WHITE[N] - AC_WHITE[bb-1]);
    }
    std::cout << ret << std::endl;

    return 0;
}

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

using namespace std;

#define fread freopen("in.txt", "r", stdin)
#define fwrite freopen("out.txt", "w", stdout)

int main ()
{
    int n;
    string str;

    scanf("%d", &n);
    getchar();
    int A, W, T, R;
    A = W = T = R = 0;
    for (int i = 0; i < n; i++) {
        cin >> str;
        if (str == "AC") A++;
        else if (str == "WA") W++;
        else if (str == "TLE") T++;
        else if (str == "RE") R++;
    }
    printf("AC x %d\n", A);
    printf("WA x %d\n", W);
    printf("TLE x %d\n", T);
    printf("RE x %d\n", R);

    return 0;
}

Measured memory_bytes: 3784
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <ctime>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
string s[10];
int go(int n){
  int res;
  printf("%d\n", n); fflush(stdout);
  scanf("%d", &res);
  if(s[n-1][res-1] == 'o') return 3;
  else if(s[n-1][res-1] == '-') return 1;
  else return 0;
}

int main(){
  srand(time(NULL));
  int N;
  cin>>N;
  REP(i, N) cin>>s[i];
  int point = 0;
  int win[10] = {};
  REP(i, N)REP(j, N) if(s[i][j] == 'o') win[i] += 1;
  for(int i = 1; i < N; i++) win[i] += win[i-1];
  int win2[10] = {};
  REP(iter, 500){
    int random = (rand() % (N * (N-1)/2));
    int hand = 0;
    for(int i = N-1; i >= 1; i--){
      //printf("%d %d:%d\n", random, i, win[i]);
      if(random < win[i] && win[i-1] <= random){
        hand = i;
        break;
      }
    }
    int get = go(hand+1);
    win2[hand] += get;
    point += get;
  }
  for(int i = 1; i < N; i++) win2[i] += win2[i-1];
  REP(iter, 500){
    int random = (rand() % point);
    int hand = 0;
    for(int i = N-1; i >= 1; i--){
      //printf("%d %d:%d\n", random, i, win[i]);
      if(random < win2[i] && win2[i-1] <= random){
        hand = i;
        break;
      }
    }
    int get = go(hand+1);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int a,b,c,d;cin>>a>>b>>c>>d;
  int alice[2],bob[2];
  int ans=0;
  if(a<c){
    alice[0]=a;
    alice[1]=b;
    bob[0]=c;
    bob[1]=d;
  }else{
    alice[0]=c;
    alice[1]=d;
    bob[0]=a;
    bob[1]=b;
  }
  if(alice[1]<=bob[0]){
    ans=0;
  }else if(alice[1]<=bob[1]){
    ans=alice[1]-bob[0];
  }else{
    ans=bob[1]-bob[0];
  }cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

int main(){
  int n,y;
  cin >> n >> y;
  bool ok = false;
  erep(i,n){
    erep(j,n){
      int s = n-j-i;
      if(i*1000+j*5000+s*10000 == y && s >= 0){
        cout << s <<" " << j << " " << i << endl;
        ok = true;
        break;
      }
    }
   if(ok) break;
  }
  if(!(ok)) cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int r;
  scanf("%d",&r);
  if(r<1200)
  {
    printf("ABC\n");
  }
  else if(r>=1200 && r<2800)
  {
    printf("ARC\n");
  }
  else
  {
    printf("AGC\n");
  }
  return 0;
}


Measured memory_bytes: 128
import sys
import fractions
import re


def lcm(a, b):
    return a / fractions.gcd(a, b) * b


#input_file = open(sys.argv[1], "r")

#for line in input_file:
for line in sys.stdin:
    ab = map(int, re.split(" +", line))
    a, b = tuple(ab)
    gcd_ab = fractions.gcd(a, b)
    lcm_ab = lcm(a, b)
    print gcd_ab, lcm_ab

Measured memory_bytes: 5892
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)

int main() {

	int A, B, C, X;
	scanf("%d%d%d%d", &A, &B, &C, &X);

	int count = 0;
	rep(a, A + 1) rep(b, B + 1) rep(c, C + 1) if (a * 500 + b * 100 + c * 50 == X) count++;

	printf("%d\n", count);

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void solve() {
        int N;
        cin >> N;
        vector<int> A(N);
        for (int i = 0; i < N; ++i) {
            cin >> A[i];
        }
        vector<int> B = A;
        sort(all(B));
        reverse(all(B));

        for (int i = 0; i < N; ++i) {
            if (A[i] == B[0]) {
                cout << B[1] << endl;
            } else {
                cout << B[0] << endl;
            }
        }


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int n, m, ans = 0;
int adj[10][10], a, b;

void dfs(int u, int c[]){
  int cc[n+1];
  for ( int i = 1; i <= n; i++){
    cc[i] = c[i];
  }
  cc[u] = 1;
  for ( int i = 1; i <= n; i++){
    if ( adj[u][i] && !cc[i]){
      dfs(i, cc);
    }
  }
  for ( int i = 1; i <= n; i++){
    if( !cc[i] ){
       return ;
    }
  }
  ans++;
  return ;
}

int main(){
  cin >> n >> m;
  for ( int i = 0; i < m; i++){
    cin >> a >> b;
    adj[a][b] = 1;
    adj[b][a] = 1;
  }

  int c[n+1];
  for (int i = 1; i <= n; i++){
    c[i] = 0;
  }

  dfs(1, c);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <queue>
#include <cmath>
#include <stack>

#define int64 long long int

using namespace std;

int main()
{
	int i, n;
	priority_queue<int> qu;

	for(i=0; i<5; i++) {
		cin >> n;
		qu.push(n);
	}
	for(i=0; i<5; i++) {
		cout << qu.top();
		qu.pop();
		if(i != 4) cout << ' ';
		else cout << '\n';
	}
	return 0;
}

Measured memory_bytes: 1212
main() {
int a,b,c;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
if ( a < b )
   if( b<c) printf("%d %d %d\n",a,b,c);
   else
     if (a<c) printf("%d %d %d\n",a,c,b);
     else printf("%d %d %d\n",c,a,b);
else
   if( a<c) printf("%d %d %d\n",b,a,c);
   else
     if (b<c) printf("%d %d %d\n",b,c,a);
     else printf("%d %d %d\n",c,b,a);
return 0;
}

Measured memory_bytes: 596
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;
import java.util.stream.LongStream;

public class Main {
    static final PrintStream so = System.out;
    static final Scanner sc = new Scanner(System.in);
    
    
    public static void main(String[] args) {
        int n = ni();
        int[] count = new int[n+1];
        for (int i = 2; i <= n; i++) {
            int[] count_i = factoring(i);
            for (int j = 0; j < count_i.length-1; j++) {
                count[j+1] += count_i[j+1];
            }
        }
        
        // 75 = 5*5*3 = 25*3 = 15*5 = 75
        int count75 = count(count, 74);
        int count24 = count(count, 24);
        int count14 = count(count, 14);
        int count4 = count(count, 4);
        int count2 = count(count, 2);

        long ans = comb(count4, 2) * (count2-2)
                 + count14 * (count4-1)
                 + count24 * (count2-1)
                 + count75;
                
        so.println(ans);
    }
    
    static int count(int[] a, int least) {
        return (int) IntStream.of(a).filter(i -> i >= least).count();
    }
    
    static long comb(int N, int R) {
        long prod1 = LongStream.rangeClosed(N-R+1, N).reduce((i, j) -> i*j).getAsLong();
        long prod2 = LongStream.rangeClosed(    1, R).reduce((i, j) -> i*j).getAsLong();
        return prod1 / prod2;
    }
    
    static int[] factoring(int argn)  {
        int n = argn;
        int[] count = new int[n+1];
        int[] primes = primes(n);
        int idx = 0;
        while (n > 1) {
            int prime = primes[idx];
            if (n % prime == 0) {
                count[prime]++;
                n /= prime;
            } else {
                idx++;
            }
        }
        return count;
    }
    
    static int[] primes(int max) {
        boolean[] isPrime = new boolean[max + 1];
        Arrays.fill(isPrime, true);
        isPrime[0] = isPrime[1] = false;
        
        for (int n = 2; n <= Math.sqrt(max); n++) {
            if (!isPrime[n])
                continue;
            
            for (int i = 2; n*i <= max; i++)
                isPrime[n*i] = false;
        }
        
        return IntStream.rangeClosed(2, max)
                        .filter(n -> isPrime[n])
                        .toArray();
    }
    
    static int ni() {
        return sc.nextInt();
    }
}


Measured memory_bytes: 27092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <complex>
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
using namespace std;
typedef long long ll;

int main(){
    int x, a;
    cin >> x >> a;
    if(x < a){
        cout << 0 << endl;
    }
    else{
        cout << 10 << endl;
    }
    return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

string s;

signed main() {
    cin >> s;
    if (s=="SUN") cout << 7 << endl;
    if (s=="MON") cout << 6 << endl;
    if (s=="TUE") cout << 5 << endl;
    if (s=="WED") cout << 4 << endl;
    if (s=="THU") cout << 3 << endl;
    if (s=="FRI") cout << 2 << endl;
    if (s=="SAT") cout << 1 << endl;
}




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

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			//Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int n = vs[0];
			int r = vs[1];
			if (n >= 10) {
				Console.WriteLine(r);
			} else {
				Console.WriteLine(r+100*(10-n));
			}


			//Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 13268
# -*- Coding: utf-8 -*-
N = input()
H = map(int,raw_input().split())


max = H[0]
ans = N
for i in xrange(1,N):
  if H[i-1]>H[i]:
    if max<H[i-1]:
      max = H[i-1]
    ans -= 1
    continue
  if max > H[i]:
    ans -= 1

print ans

Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;

    cin>>n>>a>>b;

    cout<<min(n*a,b)<<"\n";

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int N = I[0], H = I[1];
		var a = new int[N];
		var b = new int[N];
		for (var i = 0; i < N; i++)
		{
			I = G;
			a[i] = I[0];
			b[i] = I[1];
		}
		var A = a.Max();
		var B = b.Where(x => x > A).ToList();
		B.Sort((x, y) => y.CompareTo(x));
		var c = 0;
		foreach (var x in B)
		{
			if (H <= 0) break;
			H -= x;
			c++;
		}
		if (H > 0)
		{
			c += (H + A - 1) / A;
			H -= (H + A - 1) / A * A;
		}
		//Console.WriteLine(H);
		WriteLine(c);
	}
}


Measured memory_bytes: 18096
const int N = 400005;
const int LG = 21;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <bitset>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef string str;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(N);
    __ufact.resize(N);
    __rev.resize(N);
    __rev[1] = 1;
    for (int i = 2; i < N; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < N; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

void __fast_IO()
{
    #ifdef ONLINE_JUDGE
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // ONLINE_JUDGE
}

//##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**
//##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**

int n;
str s;

signed main()
{
    __fast_IO();
    cin >> n >> s;
    vi cntE(n), cntW(n);
    ll ans = 1e18;
    for (int i = 0; i < n; i++)
        cntW[i] = (i > 0 ? cntW[i - 1] : 0) + (s[i] == 'W');
    for (int i = n - 1; i >= 0; i--)
        cntE[i] = (i < n - 1 ? cntE[i + 1] : 0) + (s[i] == 'E');
    for (int i = 0; i < n; i++)
        ans = min(ans, (i > 0 ? cntW[i - 1] : 0) + (i + 1 < n ? cntE[i + 1] : 0));
    cout << ans;
}

/* Note:
Check constants at the beginning of the code.
N is set to 4e5 but be careful in problems with large constant factor.
Check corner cases.
No def int long long for now.
*/


Measured memory_bytes: 5380
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
char str[2][60];
long long gcd(long long a,long long b){
	while(a){
		b%=a;swap(a,b);
	}
	return b;
}
long long lcm(long long a,long long b){
	return a/gcd(a,b)*b;
}
int main(){
	int a;scanf("%d",&a);
	long long ret=0;
	for(int i=0;i<a;i++){
		long long b;scanf("%lld",&b);
		if(i==0)ret=b;
		else ret=lcm(ret,b);
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

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

	char hw[h][w];
	string input;

	for (auto i = 0; i < h; i++) {
		cin >> input;
		for (auto j = 0; j < w; j++) {
			hw[i][j] = input[j];
		}
	}

	bool tume1[h] = {};
	bool tume2[w] = {};

	for (auto i = 0; i < h; i++) {
		for (auto j = 0; j < w; j++) {
			if (hw[i][j] == '#') {
				tume1[i] = true;
				tume2[j] = true;
			}
		}
	}

	//output
	for (auto i = 0; i < h; i++) {
		if (tume1[i] == false) continue;
		for (auto j = 0; j < w; j++) {
			if (tume2[j] == false) continue;
			cout << hw[i][j];
		}
		cout << endl;
	}

	return 0;
}

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

    string S,T,U;
    int A,B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;

    if(S == U)
    {
        A--;
    }
    else
    {
        B--;
    }

    cout << A << " " << B;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;

int b[1000],x[1000],y[1000];

inline double SQ(double x) {return x * x;}

typedef double cost_type;
struct edge {
	int to;
	cost_type cost;
	edge(){}
	edge(int to,cost_type cost) : to(to) ,cost(cost) {}
};

typedef pair<cost_type,int> P;

void dijkstra(int s,vector<P::first_type>& cost_table,vector<vector<edge> >& edges,vector<int>* _prev = NULL){
	
	//init
	cost_table.resize((int)edges.size());
	fill(cost_table.begin(),cost_table.end(),P::first_type(INF));
	if(_prev) _prev->resize((int)edges.size());
	if(_prev) fill(_prev->begin(),_prev->end(),-1);
	
	priority_queue<P,vector<P>,greater<P> > q;
	q.push(P(0,s));
	cost_table[s] = 0;

	while(!q.empty()){
		P p = q.top(); q.pop();
		int v = p.second;
		if(cost_table[v] < p.first) continue;
		for(int i = 0; i < (int)edges[v].size(); i++){
			edge& e = edges[v][i];
			if(cost_table[e.to] > cost_table[v] + e.cost){
				cost_table[e.to] = cost_table[v] + e.cost;
				if(_prev) (*_prev)[e.to] = v;
				q.push(P(cost_table[e.to],e.to));
			}
		}
	}
}

void get_path(int t,vector<int>& prev,vector<int>& path){
	for(; t != -1; t = prev[t]) path.push_back(t);
	reverse(path.begin(),path.end());
}

int main(){
	int n;
	while(cin>>n,n){
		FOR(i,n) cin>>b[i]>>x[i]>>y[i];
		vector<vector<edge> > edges(n,vector<edge>());
		FOR(i,n) FOR(j,n){
			if(i==j) continue;
			else{
				double d = SQ(x[i]-x[j]) + SQ(y[i]-y[j]);
				if(d <= 2500) edges[i].push_back(edge(j,sqrt(d)));
			}
		}
		map<int,int> mp;
		FOR(i,n) mp[b[i]] = i;

		int n; cin>>n;
		vector<double> costs;
		vector<int> prevs;
		FOR(i,n){
			int s,g; cin>>s>>g;
			s = mp[s],g = mp[g];

			dijkstra(s,costs,edges,&prevs);
			if(prevs[g] == -1){
				puts("NA");
			} else {
			vector<int> path;
				get_path(g,prevs,path);
				FOR(j,sz(path)){
					printf("%d%c",b[path[j]],j == sz(path)-1?'\n':' ');
				}
			}
		}
	}

	return 0;
}

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

using ll = long long;
const int INF = 1e9+100;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,x,t;
	cin>>n>>x>>t;
	cout<<(n/x + (n%x != 0))*t<<'\n';
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>

using namespace std;

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

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

    int result = 0;
    for (int c_i = 0; c_i <= c; ++c_i)
        for (int b_i = 0; b_i <= b; ++b_i)
            for (int a_i = 0; a_i <= a; ++a_i)
                if (50 * c_i + b_i * 100 + 500 * a_i == x)
                    ++result;

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256