akhauriyash/Code-Regression huggingface dataset:
import java.util.*;


public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        Scanner sc = new Scanner(System.in);
		// 整数の入力
		String n = sc.next();
		int size = n.length();
		
		int count = 0;
		int index = 0;
		int s = 0;
		while(true){
		    
		    index = n.indexOf("p",s);
		    
		    if(index != -1){
		        s = index +1;
		        count++;
		    }else{
		        break;
		    }
		    
		}
		int max = size/2;
		
				// 出力
		System.out.println(max-count);
    }
}


Measured memory_bytes: 13860
#include<stdio.h>

int main(){
   int a, b;

   scanf("%d", &a);
   scanf("%d", &b);

   if (a == b) {
      printf("a == b\n");
   } else if (a > b) {
      printf("a > b\n");
   } else {
      printf("a < b\n");
   }

   return 0;
}


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

int isEmpty(void);
void push(int);
int pop(void);

int top=0, S[100];

int main()
{
  int a, b, x;
  char s[100];

  while(scanf("%s", s) != EOF){
    if(s[0] == '+' ){
      a = pop();
      b = pop();
      push(a+b);
    }
    else if(s[0] == '-'){
      a = pop();
      b = pop();
      push(b-a);
    }
    else if(s[0] == '*'){
      a = pop();
      b = pop();
      push(a*b);
    }
    else {
      x = atoi(s);
      push(x);
    }
  }

  printf("%d\n", S[top]);
  return 0;
}

int isEmpty(void)
{
  if(top == 0) return 0;
  else return 1;
}

void push(int x)
{
  top++;
  S[top] = x;
}

int pop(void)
{
  if(isEmpty() == 1){
    top--;
    return S[top+1];
  }
}

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

using namespace std;

using i64 = int64_t;
const i64 INF = i64(1e18) + 7;

int main()
{
    int n;
    cin >> n;
    vector<i64> a(n);
    for(auto& x : a)
        cin >> x;

    vector<i64> r(1, 0);
    for(int i = 0; i < n; ++i)
        r.emplace_back(r[i] + a[i]);
    for(int i = 0; i < n; ++i)
        r.emplace_back(r[i + n] + a[i]);

    i64 n_sum = accumulate(a.begin(), a.end(), 0LL);

    auto f = [&](i64 val){

        for(int i = 0; i < n; ++i){
            auto it = lower_bound(r.begin(), r.end(), r[i] + val);
            if(it >= next(r.begin(), i + n))
                continue;
            i64 s1 = *it;

            it = lower_bound(r.begin(), r.end(), s1 + val);
            if(it >= next(r.begin(), i + n))
                continue;
            i64 s2 = *it;

            i64 diff = n_sum - s2 + r[i];

            if(diff >= val)
                return true;
        }

        return false;
    };

    i64 ok = 0, ng = n_sum;
    while(abs(ok - ng) > 1){
        i64 mid = (ok + ng) >> 1;
        (f(mid) ? ok : ng) = mid;
    }

    cout << ok << endl;

    return 0;
}



Measured memory_bytes: 5732
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
  int H, W, N;

  cin >> H >> W >> N;
  int m = max(H, W);
  cout << (N+m-1)/m << endl;
  
  return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


DIV = 10**9+7

def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret
    
def mod_modify(a,mod):
    return (a+mod)%mod
    
def main():
    ans =0
    S= input()
    return "Bad" if sum([S[idx] == S[idx-1] for idx in range(1, 4)]) >= 1 else "Good"


print(main())


Measured memory_bytes: 38256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String line = br.readLine();

		String str[] = line.split("");

		long ans = 0;
		long tmp = 0;

		for (int i = 0; i < (1 << (line.length() - 1)); i++) {
			tmp = Integer.parseInt(str[0]);
			for (int j = 0; j < (line.length() - 1); j++) {
				if ((i & (1 << j)) != 0) {
					ans += tmp;
					tmp = 0;
				}

				tmp = tmp * 10 + (Integer.parseInt(str[j + 1]));
			}
			ans += tmp;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21716
#include<iostream>
using namespace std;
int main(){
   int A[5][4][11],n;
   for(int i=1; i<=4;i++)
   for(int j=1; j<=3;j++)
   for(int k=1;k<=10;k++)A[i][j][k]=0;
   cin >>n;
   for(int i=0; i<n;i++){
       int b,f,r,v;
       cin>>b>>f>>r>>v;
       A[b][f][r]+=v;
       
   }
   for(int f=1;f<=4;f++){
       if(f>1)cout<<"####################\n";
       for(int b=1;b<=3;b++){
           for(int r=1;r<=10;r++){
               cout<<" "<<A[f][b][r];
               
           }
           cout<<endl;
       }
   }
   return 0;
}


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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int h, w;
	cin >> h >> w;
	char grid[h][w];
	bool rows[h][w];
	bool cols[w][h];
	vi okr;
	vi okc;
	
	char c;
	REP(i, 0, h){
		REP(j, 0, w){
			cin >> c;
			grid[i][j] = c;
			rows[i][j] = (c== '#'?false:true);
			cols[j][i] = (c== '#'?false:true);
		}
	}
	REP(i, 0, h){
		bool ok = true;
		REP(j, 0, w){
			if(!rows[i][j]){
				ok = false;
				break;
			}
		}
		if(!ok) okr.PB(i);
	}
	
	REP(i, 0, w){
		bool ok = true;
		REP(j, 0, h){
			if(!cols[i][j]){
				ok = false;
				break;
			}
		}
		if(!ok) okc.PB(i);
	}
	
	for(auto it=okr.begin(); it < okr.end(); it++){
		for(auto it1=okc.begin(); it1 < okc.end(); it1++){
			cout << grid[*it][*it1];
		}
		cout << endl;
	}
	
	
				

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll a,b,c;
  	ci(a>>b>>c);
  ll ans=a+b+c;
  co(ans-max({a,b,c}))
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

ll comb[100][100];
void make_comb(int n) {
    erep(i, 0, n) {
        erep(j, 0, i) {
            if (j == 0 || i == j) 
                comb[i][j] = 1;
            else 
                comb[i][j] = (comb[i-1][j-1] + comb[i-1][j]);
        }
    }
}

ll t[51];
double ans;
ll cnt;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    int a, b, n;
    cin >> n >> a >> b;
    rep(i, 0, n) cin >> t[i];
    make_comb(n+1);
    sort(t, t+n, greater<ll>());
    rep(i, 0, a)
        ans += t[i];
    ans /= a;
    int a_itr = 0, a_pos = 0;
    rep(i, 0, n) {
        if (t[a-1] == t[i]) {
            a_itr++;
            if (i < a)
                a_pos++;
        }
    }
    if (a_pos == a) {
        for (a_pos = a; a_pos <= b; ++a_pos)
            cnt += comb[a_itr][a_pos];
    } else {
        cnt += comb[a_itr][a_pos];
    }
    printf("%.6f\n", ans);
    printf("%lld\n", cnt);
    return 0;
}


Measured memory_bytes: 256
n, m = gets.chomp.split(" ").map(&:to_i)
arr = Array.new(n+1){[]}
(1..m).each do |i|
    a, b = gets.chomp.split(" ").map(&:to_i)
    arr[a] << b
    arr[b] << a    
end
list = []
arr[1].each do |i|
    list << arr[i]
end
list.each do |i|
    if i.include?(n)
        puts "POSSIBLE"
        exit
    end
end
puts "IMPOSSIBLE"

Measured memory_bytes: 21500
def partition(A, p, r):
    x = A[r][1]
    i = p - 1
    for j in range(p, r):
        if A[j][1] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1

def quick_sort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quick_sort(A, p, q-1)
        quick_sort(A, q+1, r)

def merge(A, left, right, mid):
    lstl = [[A[i][0], A[i][1]] for i in range(left, mid) ] + [[None, 1000000000]]
    lstr = [[A[i][0], A[i][1]] for i in range(mid, right)] + [[None, 1000000000]]
    pl = 0
    pr = 0
    for _ in range(left, right):
        if lstl[pl][1] <= lstr[pr][1]:
            A[left + pl + pr] = lstl[pl]
            pl += 1
        else:
            A[left + pr + pl] = lstr[pr]
            pr += 1

def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, right, mid)


import sys
input = sys.stdin.readline

n = int(input())
A_q = []
A_m = []
for _ in range(n):
    card = input().split()
    A_q.append([card[0], int(card[1])])
    A_m.append([card[0], int(card[1])])

quick_sort(A_q, 0, n-1)
merge_sort(A_m, 0, n)

if A_q == A_m:
    print("Stable")
else:
    print("Not stable")

for i in range(n):
    print(" ".join(map(str, A_q[i])))
    #print(" ".join(map(str, A_m[i])))


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

using namespace std;

typedef long long int ll;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    set<string> s;

    int t;
    cin >> t;
    while(t--)
    {
        string s1;
        cin >> s1;
        s.insert(s1);
    }
    cout << s.size();

    return 0;
}


Measured memory_bytes: 19200
x, y = map(int, input().split(" "))

if y%2 == 1:
    print('No')
elif 4 * x < y:
    print('No')
elif 2 * x > y:
    print('No')
else:
    for i in range(0,x+1):
        # print("i:{}".format(i))
        if 2 * i + 4 * (x-i) == y:
            print('Yes')
            break
    else:
        print('No')
        


Measured memory_bytes: 9180
s = input().split( )
a = int(s[0])
b = int(s[1])
c = int(s[2])
if a == 1:
  if b == 1:
    print("Open")
  else:
    print("Close")
else:
  if b == 1:
    print("Close")
  else:
    if c == 1:
      print("Open")
    else:
      print("Close")



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

#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  dsu d(n);
  rep(_, m) {
    int a, b;
    cin >> a >> b;
    d.merge(a - 1, b - 1);
  }
  cout << d.groups().size() - 1 << endl;
  return 0;
}

Measured memory_bytes: 8968
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void Max(T &m, const T q) { if (m < q) m = q; }
template<typename T> void Min(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

int N;
vector<int> a;

int main()
{
    cin >> N;
    a.resize(N);
    cin >> a;
    int k = 0;
    REP(i, N) if (a[a[i] - 1] - 1 == i) k++;
    cout << k / 2 << endl;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
 
long long sum(long long n) { return n*(n+1)/2; }

int main() {
    int a;cin>>a;
    long ans=0;
  	ans=sum(a)-sum(a/3)*3-sum(a/5)*5+sum(a/15)*15;
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
#include <queue>
#include <list>
#include <set>
using namespace std;
static const int MAX = 100000;
static const int INFTY = 1 << 29;

class edge {
public:
	int t, w;
	edge(){}
	edge(int t, int w) : t(t), w(w) {}
};

vector<edge> g[MAX];
int n, d[MAX];

bool vis[MAX];
int cnt;

void bfs(int s)
{
	for (int i = 0; i < n; i++) d[i] = INFTY;
	queue<int> q;
	q.push(s);
	d[s] = 0;
	int u;
	while (!q.empty()) {
		u = q.front(); q.pop();
		for (int i = 0; i < g[u].size(); i++) {
			edge e = g[u][i];
			if (d[e.t] == INFTY) {
				d[e.t] = d[u] + e.w;
				q.push(e.t);
			}
		}
	}
}

void solve()
{
	bfs(0);

	int maxv = 0;
	int tgt = 0;
	for (int i = 0; i < n; i++) {
		if (d[i] == INFTY) continue;
		if (maxv < d[i]) {
			maxv = d[i];
			tgt = i;
		}
	}

	bfs(tgt);
	maxv = 0;
	for (int i = 0; i < n; i++) {
		if (d[i] == INFTY) continue;
		maxv = max(maxv, d[i]);
	}

	cout << maxv << endl;
}

int main()
{
	int s, t, w;
	cin >> n;

	for (int i = 0; i < n - 1; i++) {
		cin >> s >> t >> w;
		g[s].push_back(edge(t, w));
		g[t].push_back(edge(s, w));
	}

	solve();

	return 0;
}

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

int main() {
	int N, ans = 0;
	cin >> N;

	for (int i = 1; i <= N; i++) {
		if (i % 2 != 0) {
			int Q = 0;

			for (int j = 1; j <= i; j++) {
				if (i % j == 0) {
					Q++;
				}
			}

			if (Q == 8) {
				ans++;
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
# coding: utf-8
while 1:
    t,p,r=map(int,input().split())
    if t==0:
        break
    teamdata=[[0,0,i+1,set()] for i in range(t)]
    data=[]
    for i in range(r):
        b,c,a,d=input().split()
        b,c,a=map(int,(b,c,a))
        if d=='CORRECT':
            teamdata[b-1][0]+=1
            teamdata[b-1][1]+=a
            teamdata[b-1][3].add(c)
        data.append([a,b,c,d])
    for a,b,c,d in data:
        if d!='CORRECT' and (c in teamdata[b-1][3]):
            teamdata[b-1][1]+=1200
    teamdata=sorted(teamdata, key=lambda x:(-x[0],x[1],x[2]))
    for i in range(t):
        print(teamdata[i][2],teamdata[i][0],teamdata[i][1])




Measured memory_bytes: 5732
import sys
input = sys.stdin.readline
def main():
    N, M = map(int, input().split())
    W, V = [0]*N, [0]*N
    for i in range(N):
        W[i], V[i] = map(int, input().split())
    dp = [[float('inf')]*(10**5+10) for i in range(N+1)]
    # for i in range(150):
    #     dp[0][i] = 0
    dp[0][0] = 0

    for i in range(N):
        for v in range(10**5+10):
            if v - V[i] >= 0:
                dp[i+1][v] = min(dp[i+1][v], dp[i][v - V[i]] + W[i])
            dp[i+1][v] = min(dp[i+1][v], dp[i][v])
    ans = 0
    for v in range(10**5 + 10):
        if dp[N][v] <= M:
            ans = v
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 311192
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INF = 1000000007;
const int mod = 1000000007;

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

//----------------------------------------------------------------

int main()
{
    long long n;
    cin >> n;
    vector<int> a(n);
    int flag = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    for (int i = 1; i < n; i++)
    {
        if (a.at(i) == a.at(i - 1))
        {
            flag++;
        }
    }
    if (flag)
    {
        cout << "NO" << endl;
    }
    else
    {
        cout << "YES" << endl;
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
 
struct UF{
    int par[200001];
    int runk[200001];
    void init(int n){
    for(int i=0;i<=n;i++){
        par[i] = i;
        runk[i] = 0;
    }
}
int find(int n){
    if(par[n] == n)return n;
    return par[n] = find(par[n]);
}
void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x==y)return;
    if(runk[x]<runk[y]){
        par[x] = y;
    }else{
        par[y] = x;
        if(runk[x]==runk[y])runk[x]++;
    }
}
bool issame(int x,int y){
    return find(x)== find(y);
}
 
};
 
 
int main(){
    UF uni1,uni2;
    int N,K,L;
    cin >> N >> K >> L;
    uni1.init(N);
    uni2.init(N);
    int p,q;
    for(int i=0;i<K;i++){
        cin >> p >> q;
        p--,q--;
        uni1.unite(p,q);
    }
    int r,s;
    for(int i=0;i<L;i++){
        cin >> r >> s;
        r--,s--;
        uni2.unite(r,s);
    }
    using pint = pair<int,int>;
    map<pint,int> ma;
    for(int i=0;i<N;i++){
        pint p(uni1.find(i),uni2.find(i));
        ma[p]++;
    }
    for(int i=0;i<N;i++){
        pint p(uni1.find(i),uni2.find(i));
        cout << ma[p] << ' ';
    }
 
    
    
    return 0;
 
}

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

 int main()
{
   
    int n ;
    cin>>n;
    
    int odd=0;
    for(int i =1;i<=n;i++){
            int d=0;
            int v=i;
 
        while(v>0){
            v=v/10;
             d++;
 
        }
        if(d%2!=0) odd++;
    }
    cout<<odd;
   }

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

int main (void)
{
	int n;
	scanf("%d",&n);
	int *a;
	a = (int *)malloc(sizeof(int)*(n));
	int i = 0;
	int max = 0;
	int max_i = -1;
	while (i < n)
	{
		scanf("%d",&a[i]);
		if(a[i] > max)
		{
			max = a[i];
			max_i = i;
		}
		i++;
	}
	int s_max = -1;
	i = 0;
	while (i < n)
	{
		if (a[i] > s_max && i != max_i)
		{
			s_max = a[i];
		}
		i++;
	}
	i = 0;
	while (i < n)
	{
		if (i == max_i)
			printf("%d\n",s_max);
		else
			printf("%d\n",max);
		i++;
	}
	return(0);
}


Measured memory_bytes: 2304
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
n = S()
if "9" in n:
    print("Yes")
else:
    print("No")
"""
#B
n = I()
f = [0 for i in range(100002)]
for i in range(n):
    l,r = LI()
    f[l] += 1
    f[r+1] -= 1
ans = 0
for i in range(1,100001):
    f[i] += f[i-1]
    if f[i]:
        ans += 1
print(ans)
#C
"""
n = I()
d = defaultdict(int)
for i in range(n):
    a = I()
    d[a] ^= 1
d = list(d.values())
print(sum(d))
"""
#D
"""
def dfs(n,k,l,a):
    if n == 0:
        a.append(l)
    for i in range(n):
        dfs(n-1,k[:i]+k[i+1:],l+[k[i]],a)
n,m,R = LI()
r = LI()
f = [i for i in range(n)]
for i in range(R):
    r[i] -= 1
v = [[float("inf") for j in range(n)] for i in range(n)]
for i in range(n):
    v[i][i] = 0
for i in range(m):
    a,b,c = LI()
    a -= 1
    b -= 1
    v[a][b] = c
    v[b][a] = c
for k in range(n):
    for i in range(n):
        for j in range(n):
            v[i][j] = min(v[i][j],v[i][k]+v[k][j])
l = []
dfs(R,r,[],l)
ans = float("inf")
for k in l:
    d = 0
    for i in range(R-1):
        d += v[k[i]][k[i+1]]
    ans = min(ans,d)
print(ans)
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 45168
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)
sum = 0
1.upto(n) do |x|
  if a[x-1] >= b[x-1] then
    sum += b[x-1]
  else
    sum += a[x-1]
    rest = b[x-1] - a[x-1]
    if a[x] >= rest then
      sum += rest 
      a[x] -= rest
    else
      sum += a[x]
      a[x] = 0
    end
  end
end
puts sum

Measured memory_bytes: 17572
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

signed main(){
	ll N,Q;
	cin >> N >> Q;
	string S;
	cin >> S;
	ll sum[2*N-1] = {0};
	FOR(i,0,N-1){
		if(S[i] == 'A' && S[i+1] == 'C'){
			sum[2*i+1] = 1;
		}
	}
	FOR(i,0,2*N-2)sum[i+1] += sum[i];
	DEBUG(sum)
	FOR(i,0,Q){
		ll l,r;
		cin >> l >> r;
		l--;
		r--;
		cout << sum[2*r] - (2*l-1 >= 0 ? sum[2*l-1] : 0) << endl;
	}
}

Measured memory_bytes: 2640
s = list(input())
n = len(s)
list = []
#print(s)
for i in range(n-2):
  A = int(s[i]+s[i+1]+s[i+2])
  #print(A)
  B = abs(A-753)
  #print(B)
  list.append(B)
print(min(list))

Measured memory_bytes: 2940
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

count, ans = 0, 0
for a, b in sorted(AB):
    x = min(b, M - count)
    count += x
    ans += a * x
    if count == M:
        break
print(ans)


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

using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<long long int>
int main(){
   long double w,h,x,y;
   cin >> w >> h >> x >> y;
 	cout << fixed << setprecision(6) << w*h/2.0 << ' ';
 	if(x==w/2 && y==h/2)cout << 1;
 	else cout << 0;
    cout << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <cmath>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a[n];
    for (int i=0; i<n; i++) {
        int k;
        cin >> k;
        for (int j=0; j<k; j++) {
            int u;
            cin >> u;
            a[i].push_back(u);
        }
    }
    int check[m+1] = {0};
    for (int i=0; i<n; i++) {
        for (auto x: a[i]) {
            check[x]++;
        }
    }
    int cnt = 0;
    for (int i=1; i<=m; i++) {
        if (check[i] == n) cnt++;
    }
    cout << cnt << '\n';
    
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

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

    if(s[0] == t[2] && s[1] == t[1] && s[2] == t[0]) YES();
    else NO();
}

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>;
#define chmax(x,y) x = max(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    mint col = m;
    rep(i,n-k-1) col *= m-1;
    mint ans;
    combination c(200005);
    for (int i = k; i >= 0; i--) {
        mint now = col;
        now *= c(n-1,i);
        ans += now;
        col *= m-1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6356
n = int(input())
s = input()

def black():
    result = [0] * n
    count = 0
    for i in range(n):
        if s[-i-1] == '.':
            count += 1
        result[-i-1] = count
    return result + [0]

def white():
    result = [0] * n
    count = 0
    for i in range(n):
        if s[i] == '#':
            count += 1
        result[i] = count
    return [0] + result

num = [x + y for x,y in zip(black(), white())]
result = min(num)

print(result)

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n, int k) {
      if (k < 0 || k > n) return 0;
      return fact[n]*ifact[n-k];
  }
} comb(1000010);

using Graph = vector<vector<int>>;
int N, K;

// 子供の塗り方を決めていく。
mint dfs(int v, int p, const Graph& G) {
    int available_color = K - 2;
    int child_size = G[v].size() - 1;
    if (p == -1) {
        available_color = K - 1;
        child_size = G[v].size();
    }

    if (K < G[v].size()) {
        return mint(0);
    }
    
    // printf("v = %d\n", v);

    mint res = 1;
    for (auto child : G[v]) {
        if (child == p) continue;
        res *= dfs(child, v, G);
    }

    // printf("available_color, child_size = %d, %d\n", available_color, child_size);
    res *= comb.p(available_color, child_size);
    // printf("v, res = %d, %d\n", v, res.x);

    return res;  //  * comb(available_color, G[v].size());
}

int main() {
    cin >> N >> K;
    // vector<int> a(N), b(N);
    // rep(i, N) cin >> a[i] >> b[i];
    Graph G(N);
    rep(i, N-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    // cout << "here?" << endl;

    mint ans = dfs(0, -1, G) * K;
    cout << ans.x << endl;
}

Measured memory_bytes: 30080
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

bool comp2r(P a, P b) {
    if (a.second != b.second)
        return a.second > b.second;
    return a.first > b.first;
}

int main() {
    int n;
    cin >> n;
    vector<P> p(n);
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        p[i] = make_pair(a, b);
    }
    
    int l, l1, l2, r, r1, r2;
    sort(p.begin(), p.end());
    l = p[n/2].first;
    l1 = p[n/2 - 1].first;
    l2 = p[n/2].first;
    
    sort(p.begin(), p.end(), comp2r);
    r = p[n/2].second;
    r1 = p[n/2 - 1].second;
    r2 = + p[n/2].second;
    
    //cout << "[" << l << ", " << r << "]" << endl;
    //cout << l1 << " -- " << l2 << " | " << r2 << " -- " << r1 << endl;
    int ans;
    if (n % 2 == 1)
        ans = r - l + 1;
    else {
        ans = (r1 + r2) - (l1 + l2) + 1;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 4760
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine().Select(x => x - '0').ToArray();

        var kk = 0;
        var dp = new int[4][];
        for (int i = 0; i < dp.Length; ++i)
        {
            dp[i] = new int[10];
        }
        dp[0][0] = 1;
        for (int i = 0; i < s.Length; ++i)
        {
            for (int j = Math.Min(dp.Length - 1, i + 1); j > 0; --j)
            {
                dp[j][s[i]] = 0;
                for (int k = 0; k < dp[j - 1].Length; ++k)
                {
                    dp[j][s[i]] += dp[j - 1][k];
                }
                ++kk;
            }
        }
        Console.WriteLine(dp[3].Sum());
        Console.Error.WriteLine(kk);
        Console.Error.WriteLine(string.Join(" ", dp[1]));
        Console.Error.WriteLine(string.Join(" ", dp[2]));
        Console.Error.WriteLine(string.Join(" ", dp[3]));
    }
}


Measured memory_bytes: 13792
#include <bits//stdc++.h>
using namespace std;
int main(void){
    long long a,b,c,i,j,k;
    cin>>a>>b;
    cin>>i>>j;
    
    long long a1,a2;
    a1=a*b/2;
    if(a%2==0||b%2==0){
    cout<<a1<<" ";
    if(a/2==i&&b/2==j&&a%2==0&&b%2==0)
    cout<<"1";
    else
    cout<<"0";
    }
    
    else{
    cout<<a1<<".5"<<" ";
    cout<<"0";
    }
    cout<<endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    vector<string> s = {"SUN",
                        "MON",
                        "TUE",
                        "WED",
                        "THU",
                        "FRI",
                        "SAT",
                        "SUN"};
    string t;
    cin >> t;
    for (ll i = 0; i < s.size(); i++)
    {
        if (t == s[i])
        {
            cout << 7-i << endl;
            exit(0);
        }
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int x,y,a[17][17],s,i,j;
void dfs(int y1,int x1){
  if(a[y1][x1]==1)return;
  if(x1<1||x1>x)return;
  if(y1>=y){s++;return;}
  if(a[y1][x1]==2)dfs(y1+2,x1);
  else {if(a[y1+1][x1]!=1)dfs(y1+1,x1);
  if(a[y1+1][x1+1]==0)dfs(y1+1,x1+1);
  if(a[y1+1][x1-1]==0)dfs(y1+1,x1-1);}
  return;
}
int main(){
  while(cin>>x>>y,x){
    for(s=0,i=0;i<17;i++)for(j=0;j<17;j++)a[i][j]=0;    
    for(s=0,i=1;i<=y;i++)for(j=1;j<=x;j++)cin>>a[i][j];
    for(i=1;i<=x;i++){if(a[1][i]==0)dfs(1,i);}
    cout<<s<<endl;
  }
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll, ll>
#define pb push_back
#define ll long long
#define ld long double	
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e18
ll power(ll num, ll g, ll mod) {
	if (g == 0)return 1;
	if (g % 2 == 1)return (num * power((num * num) % mod, g / 2, mod)) % mod;
	return power( (num * num) % mod, g / 2, mod);
}

int main(){
	string s;
	int k;
	cin >> k;
	cin >> s;
	if (s.size() <= k) cout << s;
	else cout << s.substr(0, k) << "...";
}

Measured memory_bytes: 3600
/*
	RAone00
	Rohit sharma
	*/

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

	typedef long long ll;
	typedef long double ld;
	typedef pair < ll, ll > pll;
	typedef vector < vector < ll > > matrix;
	typedef vector < ll > vll;

	#define pb push_back
	#define debug(x) cout << (#x) << " is " << (x) << endl
	#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

	const ll mod = 1e9 + 7;
	const ll inf = LLONG_MAX;
	const ll N = 1e5 + 10;

	
	int main() {
	    fast_io();
	    ll n, a, b;
	    cin >> n >> a >> b;
	    cout << ((n / (a + b) * a) + min((n % (a + b)), a)) << "\n";
	    return 0;
	}

 

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    string s;
    int k;
    cin>>s>>k;
    for(int i=0;i!=s.size()-1 && k>0;++i){
        if(k<'z'-s[i]+1 || s[i]=='a')
            continue;
        else{
            k-='z'-s[i]+1;
            s[i]='a';
        }
    }
    k%=26;
    if(k>'z'-s[s.size()-1])
        k-=26;
    s[s.size()-1]=char(s[s.size()-1]+k);
    cout<<s<<endl;
}

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

/*** Typedef ***/
typedef long long ll;
typedef unsigned long long ull;

/*** Loops ***/
#define ffit(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)
#define ff1(i,a,b) for(ll i = a; i <b; i++)
#define ff2(i,a,b) for(ll i = b-1; i >= a; i--)
#define ff3(i,a,b,m) for(ll i = a; i <=b; i+=m)
#define ipar(ar,n) ll ar[n]; ff1(i,0,n) cin>>ar[i];
#define opar(ar,n) ff1(i,0,n) cout<<ar[i]<<" ";
#define foRev(num) for(ll i = num - 1; i >= 0; i--)
#define forIn(arr, num) for(ll i = 0; i < num; i++) sc1(arr[i]);
#define forIn1(arr, num) for(ll i = 1; i <= num; i++) sc1(arr[i]);
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define apnt(arr, num) for(ll i = 0; i < num; i++) cout << arr[i] << (i + 1 < num ? ' ' : '\n');

/*** Define Values ***/
//#define mod 1000000007
#define PI acos(-1.0)
#define eps 1e-7
#define size1 15

/*** STLs ***/
#define rsz(x...) resize(x)
#define ins(x...) insert(x)
#define ft() front()
#define bk() back()
#define eb(x...) emplace_back(x)
#define lb(x...) lower_bound(x)
#define ub(x...) upper_bound(x)
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define mem(name, value) memset(name, value, sizeof(name))
#define endl " \n"

/*** STLs ***/
typedef vector <ll> vll;
#define vvll vector<vll>
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll, ll> > vpll;

///vector<vector<int>> v(10, vector<int>(20,500)); 2d vector initialization. of 10 rows and 20 columns, with value 500.

/*** Sorts ***/
#define all(v) (v).begin(), (v).end()
#define rev(v) reverse(all(v))
#define srt(v) sort(all(v))
#define srtgrt(v) sort(all(v), greater<ll>())
#define prsrt greater<pair<int,int>>()
/*** Some Prints ***/
#define q2(n) (n%2)==0
#define ip(n) ll n; cin>>n;
#define en cout << '\n';
#define no cout << "NO" << '\n'
#define yes cout << "YES" << '\n'
#define case cout << "Case " << t++ << ": ";
#define ps(x,y)         fixed<<setprecision(y)<<x
#define inf             1e18
#define debug(x) cout << '>' << #x << ':' << x << endl;
//const ll N = 1e6 + 9;
#define w(x)             ll x; cin>>x; while(x--)
//#define SIZE_INT sizeof(int) * 4

int main()
{
    ip(n);ipar(a,n);
    sort(a,a+n);
    ll k = abs(a[0] - a[n-1]);
    cout<<k;
return 0;
}








Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <stack>
#include <math.h>

using namespace std ;

long long  GreatestCommonDivisor(long long  a, long long  b)
{
	long long  temp;

	if(a < b)
	{
		// 交换两个数，使大数放在a的位置上。
		temp = a;
		a = b;
		b = temp;
	}

	while(b != 0)
	{
		// 利用辗转相除法，直到b为0为止。
		temp = a % b;
		a = b;
		b = temp;
	}

	return a;
}

long long LeastCommonMultiple(long long  a, long long b)
{
	long long t=GreatestCommonDivisor(a, b);
	long long t1=a,t2=b;
	if(t1>t2) t1/=t;
	else t2/=t;
	if(t1==t2)
	return t1;
	else 
	return t1*t2;
}
long long a[105];
int main()
{
	int n;
	cin>>n;
    long long ans;
	for(int i=0;i<n;i++)
	cin>>a[i];
	ans = a[0];
	for(int i=1;i<n;i++)
	{
	ans =  LeastCommonMultiple(ans,a[i]);  
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  bool ok=true, C=false;
  int n=s.length();
  if( s[0]!='A' ) ok=false;
  if( s[1]<'a' ) ok=false;
  for(int i=2; i<(int)s.length(); i++) {
     if (!ok) break;
     if( s[i]<'a' ) {
        if( i<n-1&&s[i]=='C'&&!C ) C=true;
        else ok=false;
     }
  }
  if( ok&&C ) cout<<"AC"<<'\n';
  else cout << "WA"<<'\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Station{
	int from, to, cost, time;
}
class Answer{
	int from, to, costOrTime;
}
public class Main {
	/**
	 * @param n üHÌ{ E
	 * @param m wÌÂ V
	 * @param cost li
	 * @param time Ô
	 * @param numberOfAnswer NGÌ
	 **/
	static Scanner sc = new Scanner(System.in);
	static int n, m, cost, time, numberOfAnswer;
	static final int INF = 10000;
	static Station []st;
	static Answer []ans;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}

	//¸_ÌÔÍP©çÅ é±ÆÉÓI
	static boolean read(){
		n = sc.nextInt(); m = sc.nextInt();
		if(n == 0 && m == 0)
			return false;
		st = new Station[2*n+1];
		for(int i = 1; i < n+1; i++){
			st[i] = new Station();
			st[i].from = sc.nextInt();
			st[i].to = sc.nextInt();
			st[i].cost = sc.nextInt();
			st[i].time = sc.nextInt();
		}
		for(int i = n+1; i < 2*n+ 1; i++){
			st[i] = new Station();
			st[i].from = st[i - n].to;
			st[i].to = st[i - n].from;
			st[i].cost = st[i - n].cost;
			st[i].time = st[i - n].time;
		}
		numberOfAnswer = sc.nextInt();
		ans = new Answer[numberOfAnswer + 1];
		for(int j = 1; j < numberOfAnswer+1; j++){
			ans[j] = new Answer();
			ans[j].from = sc.nextInt();
			ans[j].to = sc.nextInt();
			ans[j].costOrTime = sc.nextInt();
		}
		return true;
	}
	static void solve(){
		for(int i = 1; i < numberOfAnswer+1; i++){
			if(ans[i].costOrTime == 1){
				shortestTime(ans[i].from, ans[i].to);
			}else{
				cheapestCost(ans[i].from, ans[i].to);
			}
		}
	}
	static void shortestTime(int from, int to){
		int []d = new int[m+1];
		for(int i = 1; i < m+1; i++)
			d[i] = INF;
		d[from] = 0;
		while(true){
			boolean update = false;
			for(int i = 1; i < 2*n+1; i++){
				Station station = st[i];
				if(d[station.from] != INF && d[station.to] > d[station.from] + station.time){
					d[station.to] = d[station.from] + station.time;
					update = true;
				}
			}
			if(!update) break;
		}
		System.out.println(d[to]);
	}
	static void cheapestCost(int from, int to){
		int []d = new int[m+1];
		for(int i = 1; i < m+1; i++)
			d[i] = INF;
		d[from] = 0;
		while(true){
			boolean update = false;
			for(int i = 1; i < 2*n+1; i++){
				Station station = st[i];
				if(d[station.from] != INF && d[station.to] > d[station.from] + station.cost){
					d[station.to] = d[station.from] + station.cost;
					update = true;
				}
			}
			if(!update) break;
		}
		System.out.println(d[to]);
	}
}

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

typedef long long int ll;

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

    for(ll i = n - 1;i >= 0;i--){
        ll t = 0;
        for(ll j = i;j < n;j += i + 1){
            t += b[j];
        }
        if(t % 2 == 0 && a[i] == 1 || t % 2 == 1 && a[i] == 0){
            b[i]++;
            m++;
        }
    }

    cout << m << "\n";
    for(ll i = 0;i < n;i++){
        if(b[i] != 0){
            cout << i + 1 << " ";
        }
    }

    return 0;
}

Measured memory_bytes: 3968