akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;

typedef long long ll;
const ll inf = 1e15;

int main() {
    ll l,r;
    scanf("%lld %lld",&l,&r);
    ll ans = 2019;
    bool flag = false;
    for (ll i = l; i < r; i++) {
        for (ll j = i + 1; j <= r; j++) {
            ll tmp = (i * j) % 2019;
            ans = min(ans,tmp);
            if (ans == 0) {
                flag = true;
                break;
            }
        }
        if (flag) break;
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 256
N, K=map(int, input().split())
A=list(map(int, input().split()))
A+=A
tmp=[0]*2001
S1=[0]*N
S2=[0]*N
for i in range(1, N):
  tmp[A[i-1]]+=1
  S1[i]=sum(tmp[A[i]+1:])
tmp[A[-1]]+=1
S2[0]=sum(tmp[A[0]+1:])
for i in range(1, N):
  tmp[A[i-1]]+=1
  S2[i]=sum(tmp[A[i]+1:])
S2=[S2[i]-S1[i] for i in range(N)]
print((K*sum(S1)+sum(S2)*K*(K-1)//2)%(10**9+7))

Measured memory_bytes: 3316
#include <iostream>

using namespace std;

int main()
{
    int a,b,x,y,r;
    cin>>a>>b>>x>>y>>r;
    if(0<=x-r&&x+r<=a&&0<=y-r&&y+r<=b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3116
import java.io.*;
import java.lang.*;
import java.util.*;
import java.math.*;

class Main {
	static BufferedReader jvin = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter jvout = new PrintWriter(System.out);

	static int maxN = (int)1E5+5;
	int n;
	int[] a;

	public static void main(String[] args) throws IOException {
		Main instance = new Main();
		instance.passStaticVar();
	}

	public void passStaticVar() throws IOException {
		n = Integer.parseInt(jvin.readLine());
		a = new int[n+1];
		for (int i = 1; i <= n; ++i) 
			a[i] = Integer.parseInt(jvin.readLine());
		
		boolean[] marked = new boolean[n+1];
		for (int i = 1; i <= n; ++i)
			marked[i] = false;
		int result = 0, i = 1;
		for ( ; !marked[i] && i != 2; i = a[i]) {
			marked[i] = true;
			++result;
		}
		if (i == 2) jvout.println(result);
		else jvout.println("-1");
		jvout.flush();
	}
}


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

int main(void) {
    int64_t N, K;
    int64_t a,b;

    cin >> N >> K;

    vector<int64_t> ab(200000,0);
    for(int i=0;i<N;i++) {
        cin >> a >> b;
        ab[a-1] += b;
    }

    b = 0;
    for(int i=0;;i++) {
        b += ab[i];
        if(b >= K) {
            a = i+ 1;
            break;
        }
    }

    cout << a << "\n";

    return 0;
}


Measured memory_bytes: 1792
using System;
using System.Linq;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());       //??´??°???

            //?????????????????\???
            int[] a = new int[n];
            string b = Console.ReadLine();
            string[] c = b.Split(' ');
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(c[i].ToString());
            }

            //????°????????????§??????????¨????????¨????

            int min = a.Min();      //a?????°?????¨???????????????
            int max = a.Max();
            long sum = 0;
            for(int i = 0; i <a.Length; i++)        //Length?????????????????±?????????????¢??????????????????????
            {
                sum += a[i];
            }
        Console.WriteLine(min + " " + max + " " + sum);

        }
    }
}

Measured memory_bytes: 10156
using System;
class program
{
    static void Main(string[] args)
    {
      string[] s_wk = Console.ReadLine().Split(' ');
      int A = int.Parse(s_wk[0]);
      int B = int.Parse(s_wk[1]);
      int result = 0;
      if( A > B )
      {
        result += A;
        A--;
      }
      else
      {
        result += B;
        B--;
      }
      if( A > B )
      {
        result += A;
      }
      else
      {
        result += B;
      }
      Console.WriteLine(result);
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int ans,cnt;
set<int>r;
map<int,set<int>>dp;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    cin>>a>>b;
    while(a--){
        int b,c,d;
        cin>>b>>c>>d;
        dp[b].insert(d);
        dp[c].insert(-d);
    }
    for(auto &p:dp){
        for(int i:p.second){
            if(i>0){
                r.insert(i);
            }
        }
        ans=max(ans,(int)r.size());
        for(int i:p.second){
            if(i<0){
                r.erase(-i);
            }
            else{
                r.insert(i);
            }
        }
        ans=max(ans,(int)r.size());
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 19072
#include<stdio.h>


int main(){

    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if((a==7&&b==5&&c==5) || (a==5&&b==7&&c==5) || (a==5&&b==5&&c==7))printf("YES\n");
    else printf("NO\n");

    return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		boolean[][] f = new boolean[n][10];

		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < 10; ++j) {
				f[i][j] = in.nextInt() == 1;
			}
		}

		int[][] p = new int[n][11];
		for(int  i = 0; i < n ; ++i) {
			for(int j = 0; j < 11; ++j) {
				p[i][j] = in.nextInt();
			}
		}


		long max = Long.MIN_VALUE;
		for(int mask = 1; mask < 1024; ++mask) {

			long localMax = 0;
			for(int s = 0; s < n; ++s){
				int cnt = 0;
				for(int b = 0; b < 10; ++b) {
					if((mask & (1 << b)) != 0 && (f[s][b])) {
						++cnt;
					}
				}


				localMax += p[s][cnt];
			}

			
			max = Math.max(max, localMax);
		}

		System.out.println(max);

	}


}

Measured memory_bytes: 26148
N = int(input())
h = [int(x) for x in input().split()]
count = 0
con = 0
while True:
    for i in range(N):
        if h[i] > 0:
            h[i] -= 1
            con = 1
        elif h[i] <= 0:
            if con == 1:
                count += 1
            con = 0
    if con == 1:
        count += 1
    con = 0
    if not any(h):
        break

print(count)


Measured memory_bytes: 9192
object Main extends App {

  import scala.io.StdIn._

  val n = readLong()
  val s = readLong()

  val rt = Math.sqrt(n).toLong

  def digitSum(b : Long, n : Long) : Long = if (n < b) n else digitSum(b , n / b) + n % b

  def checkOne = if (n == s) Some(n + 1) else None

  def searchFirstHalf(now : Long):Option[Long] = {
    if (now >= rt)  None
    else if (now > 1 && digitSum(now, n) == s) Some(now)
    else searchFirstHalf(now + 1)
  }

  def searchSecondHalf(now : Long) : Option[Long] = {
    if (now <= 0) None
    else {
      val b = (n + now - s) / now
      if (b > 1 && digitSum(b, n) == s) {
        Some(b)
      }
      else searchSecondHalf(now - 1)
    }
  }

  val calc = if (n < s) None else checkOne orElse searchFirstHalf(2) orElse searchSecondHalf(rt)

  println(calc getOrElse -1)
}

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

using namespace std;

int main()
{
	int sum, n;
	cin >> sum >> n;

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

	make_heap(vec.begin(), vec.end());

	int result = vec.front() * 2 - sum - 1;

	if (result > 0){
		cout << result;
	}
	else{
		cout << 0;
	}

	return 0;
}

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


const int maxn = 105;
const ll mod = 1e9 + 7;
int N;
ll K;


struct Matrix{
  ll A[maxn][maxn];
  int n;

  Matrix(){}

  Matrix(int n_): n(n_) {
    for(int i = 0; i < n; ++i)
      for(int j = 0; j < n; ++j)
        A[i][j] = 0;
  }

  Matrix operator * (const Matrix& o) const {
    Matrix ret(n);
    for(int i = 0; i < n; ++i)
      for(int j = 0; j < n; ++j)
        for(int k = 0; k < n; ++k){
          ll c = A[i][k] * o.A[k][j] % mod;
          ret.A[i][j] = (ret.A[i][j] + c) % mod;
        }
    return ret;
  }

  static Matrix identity(int n){
    Matrix ret(n);
    for(int i = 0; i < n; ++i)
      ret.A[i][i] = 1;
    return ret;
  }

  Matrix operator ^ (long long k) const {
    Matrix ret = identity(n);
    Matrix a = *this;
    while(k){
      if(k & 1)ret = ret * a;
      a = a * a;
      k /= 2;
    }
    return ret;
  }

};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> K;
    Matrix M = Matrix(N);
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < N; ++j){
            cin >> M.A[i][j];
        }
    }
    ll ret = 0;
    M = M ^ K;
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < N; ++j){
            ret = (ret + M.A[i][j]) % mod;
        }
    }
    cout << ret << endl;
}


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

/*
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <ctype.h>
*/


using namespace std;

typedef pair<int , int > pii;
typedef pair<long , long> pll;
typedef pair<pii , int > piii;
typedef pair<pll , long > plll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector <pii> vii;
typedef vector<pll> vll;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned long long int ulli;
typedef long long int lli;
typedef double d;
typedef float f;
typedef string s;
typedef char ch;
typedef pair<int,ll> pill;

#define loop(n) for(int i = 0; i < (n); i++)
#define lp(x , s , e) for(int x = (s); x < (e); x++)
#define lpe(x , s , e) for(int x = (s); x <= (e); x++)
#define readline(s) getline(cin,s)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define clr(x , val) memset((x) , (val) , sizeof(x))
#define endl '\n'

ll power(ll a, ll b)
{
    ll res = 1;
    for(int i = 0; i<b; i++)
       res *= a;

    return res;
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n , k;
    cin >> n >> k;
    ll times = n / k;
    n = n - (times * k);
    while (true)
    {
    	if (n - k < 0)
    	{
    		if (abs(n - k) < n)
    		{
    			cout << abs(n - k) << endl;
    			return 0;
    		}
    		cout << n << endl;
    		return 0;
    	}
    	n = abs(n - k);
    }

    return 0;
}


Measured memory_bytes: 256
# 解説
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline

class BIT:
    def __init__(self, n):
        #A1 ... AnのBIT(1-indexed)
        self.BIT = [0] * (n + 1)

    #A1 ~ Aiまでの和 O(logN)
    def query(self, idx):
        res_sum = 0
        while idx > 0:
            res_sum += self.BIT[idx]
            idx -= idx & (-idx)
        return res_sum

    #Ai += x O(logN)
    def add(self, idx, x):
        while idx <= n:
            self.BIT[idx] += x
            idx += idx&(-idx)
        return

n, q = map(int, input().split())
a = list(map(int, input().split()))
pi = [-1] * (n + 1)  # 各数について最後に出てきた場所
ps = [[] for i in range(n)]

for i in range(n):
    l = pi[a[i]]
    if l != -1:
        ps[l].append(i)
    pi[a[i]] = i

qs = [[] for i in range(n)]
for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    qs[l].append((r, i))

d = BIT(n)
ans = [0] * q

for x in range(n - 1, -1, -1):
    for y in ps[x]:
        d.add(y, 1)
    
    for r, i in qs[x]:
        ans[i] = (r - x + 1) - d.query(r)

print(*ans)
    

Measured memory_bytes: 241604
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>

using namespace std;

long long a, b, c, d;

void solve()
{
    cin >> a >> b >> c >> d;
    if (d < b)
    {
        cout << "No\n";
        return;
    }
    if (a < b)
    {
        cout << "No\n";
        return;
    }
    long long g = __gcd(b, d);
    long long k = (a - c) / g;
    if ((a - c) % g == 0) k--;
    if (a - k * g < b) cout << "No\n";
    else cout << "Yes\n";
}

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        solve();
    }
}


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

int main() {
	string vec;
  cin >> vec;
  int sum = 0;
  for (int i =0; i < vec.size();i++) {
    
    if (vec.at(i) == '1'){
      ++sum;
    }
  }
    cout << sum << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
const int inf = 1001001001;

int main()
{
  int n; cin >> n;
  int ans = -inf;
  int mi = inf;
  vector<int> a(n, 0);
  rep(i, n) cin >> a[i];

  mi = a[0];
  for (int i=1; i<n; i++) {
    ans = max(ans, a[i]-mi);
    mi = min(mi, a[i]);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3552
#include<stdio.h>
#include<limits.h>
#define LIM  667000
int P,C[6] = {1,5,10,50,100,500};
int N[6],R[6],limit;
int clerk[LIM];
int i,j;
  

int getChange(int sum){ // clerk
  int ret = 0;
  int l;
  for(l=5;l>=0;l--){
    if(sum >= C[l]){
      ret += sum/C[l];
      sum -= sum/C[l]*C[l];
    }    
  }
  return ret;
}

int getChangeBy(int sum){
  int ret = 0;
  int index = sum;
  int e;
  for(e = 0;e<6;e++)R[e] = 0;
  for(e=5;e>=0;e--){
    if(sum >= C[e] && N[e] != 0){
      R[e] = sum/C[e]>N[e]?N[e]:sum/C[e];
      sum -= R[e]*C[e];
ret += R[e];      
    } 
  }
  if(sum != 0)return -1;
  return ret;
}

void createChange(){
  for(i=0;i<LIM;i++)clerk[i] = 0;
  int B,f;
  for(f=1;f<666001;f++){  
    B = getChange(f);
    clerk[f] = B;
    //if(f < 100)printf("%d\n",clerk[f]);
  }

}


int main(){
  createChange();
 
  while(scanf("%d",&P) && P){
    int cnt,pay,ans,res;

 
    
     limit = 0;
     int u;
     for(u=0;u<6;u++){
       scanf("%d",&N[u]);
       
       limit += N[u]*C[u];
     }

    
    ans = INT_MAX;
    for(i=0;i<limit;i++)clerk[i] = -1;
    for(i=P;i<=limit;i++){
      cnt = getChangeBy(i); 
      if(cnt == -1 || ans <= cnt)continue;
      pay = 0;
      for(j = 0;j<6;j++)pay += C[j]*R[j];
      if(clerk[pay-P] == -1)clerk[pay-P] = getChange(pay-P);
      if(cnt+clerk[pay-P] < ans){
	ans = cnt+clerk[pay-P];
      }
    }
    printf("%d\n",ans);

  }
  return 0;
}

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

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

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

int main(){
  int N;
  cin >> N;
  cout << 0 << endl;
  string befres;
  cin >> befres;
  if (befres=="Vacant"){
    return 0;
  }
  int befnum = 0;
  int u=N-1, l=0;
  while (true){
    int check = (u+l)/2;
    if (check==befnum){
      check++;
    }
    string res;
    cout << check << endl;
    cin >> res;
    if (res == "Vacant"){
      return 0;
    }
    if (abs(check-befnum)%2==0){
      if ((res==befres&&check>befnum)||(res!=befres&&check<befnum)){
        l = check;
      } else {
        u = check;
      }
    } else {
      if ((res==befres&&check>befnum)||(res!=befres&&check<befnum)){
        u = check;
      } else {
        l = check;
      }
    }
    befres = res;
    befnum = check;
  }
}


Measured memory_bytes: 852
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <numeric>
#include <array>
#include <queue>
#include <set>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

int main()
{
    int N, A, B;
    cin >> N >> A >> B;

    cout << min( A*N, B ) << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    private static int d;
    private static int type = 26;

    private static int[] c;
    private static int[][] s;

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        d = Integer.parseInt(scan.next());
        c = new int[type];
        for (int i = 0; i < type; i++) {
            c[i] = Integer.parseInt(scan.next());
        }
        s = new int[d][type];
        for (int i = 0; i < d; i++) {
            for (int j = 0; j < type; j++) {
                s[i][j] = Integer.parseInt(scan.next());
            }
        }
        scan.close();

        int[] ans = createInitSol();

        for (int i = 0; i < d; i++) {
            System.out.println(ans[i] + 1);
        }
    }

    private static long calcTotalScore(int[] t, int lastDay) {
        int[] prevContest = new int[type];
        Arrays.fill(prevContest, -1);
        long score = 0;
        for (int i = 0; i <= lastDay; i++) {
            score += s[i][t[i]];
            prevContest[t[i]] = i;
            for (int j = 0; j < type; j++) {
                score -= c[j] * (i - prevContest[j]);
            }
        }
        return score;
    }

    private static int[] createInitSol() {
        int[] initSol = new int[d];

        for (int i = 0; i < d; i++) {
            int bestType = -1;
            long bestScore = Long.MIN_VALUE;
            for (int j = 0; j < type; j++) {
                initSol[i] = j;
                long score = calcTotalScore(initSol, i);
                if (score > bestScore) {
                    bestScore = score;
                    bestType = j;
                }
            }
            initSol[i] = bestType;
        }

        return initSol;
    }

}


Measured memory_bytes: 43260
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	s := sc.Text()

	ans := 0
	for i := 1; i < n-1; i++ {
		s1 := s[:i]
		s2 := s[i:]

		cnt := 0
		for c := 'a'; c <= 'z'; c++ {
			if strings.Contains(s1, string(c)) && strings.Contains(s2, string(c)) {
				cnt++
			}
		}
		if ans < cnt {
			ans = cnt
		}
	}
	fmt.Println(ans)
}


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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, a, n) for (int i = (n); i < (a); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

template<typename T,typename U>
void Printarray(T f,U n){
  for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];
}

void flagfunc(bool flag,string A,string B){
  flag ? cout<<A<<endl : cout<<B<<endl;
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

void flag3func(bool flag){
  flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n,m,x;cin>>n>>m>>x;
  int a=0,b=0,hoge;
  for (int i = 0; i < m; ++i){
  	cin>>hoge;
  	//0縺ｫ騾ｲ繧薙〒繧・￥
  	if(hoge<x)a++;
  	//n縺ｫ騾ｲ繧薙〒繧・￥
  	if(hoge>x)b++;
  	// cout<<a<<" "<<b<<endl;
  }
  // cout<<a<<" "<<b<<endl;
  cout<<min(a,b)<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <vector>
#include <deque>
using namespace std;
int main(){
	deque<char> a;
	string s;
	cin>>s;
	for (int i=0;i<s.size();i++){
		if (s[i]=='0'){
			a.push_back('0');
		}
		else if (s[i]=='1'){
			a.push_back('1');
		}
		else if (s[i]=='B' && a.size()!=0){
			a.pop_back();
		}
	}
	while (!a.empty()){
		cout<<a.front();
		a.pop_front();
	}
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	VI A(N);
	double ue = 1,sita=0;
	REP(i, N) {
		double a;
		cin >> a;
		//ue *= A[i];
		sita += 1.0 / a;
	}
	
	printf("%f", ue / sita);

	return 0;
}



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

int max(int , int ) ;

int main()
{
	string s1,s2,ans;
	cin>>s1>>s2;
	int l1=s1.length();
	int l2=s2.length();
	int dp[l1+1][l2+1] ;
	for(int i=0;i<=l1;i++) dp[i][0]=0;
	for(int j=0;j<=l2;j++) dp[0][j]=0;
	for(int i=1;i<=l1;i++)
	{
		for(int j=1;j<=l2;j++)
		{
			 if(s1[i-1]==s2[j-1]) dp[i][j]=1+dp[i-1][j-1] ;
			else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		//	cout<<dp[i][j]<<" ";
		}
		//cout<<endl;
	}
	int i=l1,j=l2;
	while(i>0 && j>0)
	{
		while(i>0 && j>0)
		{
			if(s1[i-1]==s2[j-1]) 
			{
				i--;
				j--;
				ans=ans+s1[i];
			}
			else
			{
				if(dp[i][j]==dp[i-1][j]) i--;
				else j--;
			}
		}
	}
	reverse(ans.begin(),ans.end());
	cout<<ans;
	return 0;
}
int max(int a, int b)
{
	if(a>=b) return(a);
	return(b);
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

inline int mul (int a, int b, int m = MOD) {
    return ((ll)a * b) % m;
}

inline int binpow (int a, int n, int m = MOD) {
    int ans = 1;
    for (; n; n >>= 1) {
        if (n & 1) ans = mul(ans, a, m);
        a = mul(a, a, m);
    }
    return ans;
}

inline void add (int &a, int x, int m = MOD) {
    a += x;
    if (a >= m) a -= m;
    if (a < 0) a += m;
}

inline int sum (int a, int b, int m = MOD) {
    a += b;
    if (a >= m) a -= m;
    if (a < 0) a += m;
    return a;
}

inline int inv (int x, int m = MOD) {
    return binpow(x, m - 2, m); /// only if m is prime
}



main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    int ans = 0;
    vector <int> cnt(k + 1);
    for (int i = 1; i <= k; i++) {
        cnt[i] = binpow(k / i, n);
    }
    for (int i = k; i > 0; i--) {
        for (int j = i + i; j <= k; j += i) {
            add(cnt[i], -cnt[j]);
        }
        add(ans, mul(cnt[i], i));
    }
    cout << ans << '\n';
}


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

using namespace std;

using ll = long long;

int main() {
    ll n;
    cin >> n;

    std::map<ll, ll> map_e, map_o;

    {
        ll tmp;
        for (ll i = 0; i < n; ++i) {
            cin >> tmp;
            if (i % 2 == 0) {
                ++map_e[tmp];
            } else {
                ++map_o[tmp];
            }
        }
    }

    const auto calc_mode = [](const auto &m) {
        static auto mode = std::make_pair<ll, ll>(0, 0);
        mode.first = mode.second = 0;
        for (const auto &e : m) {
            if (e.second > mode.second) { mode = e; }
        }
        return std::move(mode);
    };

    const auto mode_e = calc_mode(map_e);
    const auto mode_o = calc_mode(map_o);

    if (mode_e.first != mode_o.first) {
        cout << n - mode_e.second - mode_o.second << endl;
        return 0;
    }

    map_e.erase(mode_e.first);
    map_o.erase(mode_o.first);

    const auto mode_second_e = calc_mode(map_e);
    const auto mode_second_o = calc_mode(map_o);

    const auto ans = std::min(n - mode_second_e.second - mode_o.second, n - mode_e.second - mode_second_o.second);

    cout << ans << endl;

    return 0;
}


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

typedef long long ll;
const int INF = 1e9;

using namespace std; 

#define REP(inc, bgn, end) for (int inc = bgn; inc < end; inc++)

int main() {
    int n;
    cin >> n;
    vector<int> p(n), q(n), a(n);
    REP(i, 0, n) cin >> p[i];
    REP(i, 0, n) {
        cin >> q[i];
        a[i] = i + 1;
    }
    
    map<vector<int>, int> mp;
    do {
        mp[a] = mp.size();
    } while (next_permutation(a.begin(), a.end()));

    int ans = abs(mp[p] - mp[q]);
    cout << ans << endl;
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int t[33];
int d[110];

int dp[110][33];

int main(void){
	int T,N;
	while(cin >> T){
		if(T==0)
			break;
		rep(i,T) cin >> t[i];
		rep(i,110) d[i]=24;
		rep(i,110)rep(j,33) dp[i][j]=inf;
		cin >> N;
		rep(i,N){
			int D,M;
			cin >> D >> M;
			D--;
			d[D]=min(d[D],M);
		}
		dp[0][0]=0;
		rep(i,100){
			for(int j=1;j<T;++j){
				if(t[j]<=d[i])
					dp[i+1][(j+1)%T]=min(dp[i+1][(j+1)%T],dp[i][j]);
				dp[i][0]=min(dp[i][0],dp[i][j]+1);
			}
			dp[i+1][1]=min(dp[i+1][1],dp[i][0]);
		}
		int ans=inf;
		rep(i,T) ans=min(ans,dp[100][i]);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define DEKAI 1000000007
/* ┗(^o^)┛ｗｗｗｗｗ┏(^o^)┓ﾄﾞｺﾄﾞｺﾄﾞｺﾄﾞｺｗｗｗｗｗ */

int main(){
	int n;
	cin>>n;
	set<string> s;
		int memo=0;
		string x,x2;
	lp(i,n){
		cin>>x;
		if(i!=0){
			if(x[0]!=x2[x2.size()-1]) memo=1;
		}
		decltype(s)::iterator it = s.find(x);
		if(it!=s.end()) memo=1;
		else s.insert(x);
		x2=x;
	}
	if(memo==1) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

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

const int N=3010;
double T[N],L;
int n;
double Pi=acos(-1.0)*2;

int main(){
	scanf("%d %lf",&n,&L);L*=2;
	for(int i=1;i<=n;i++) scanf("%lf",&T[i]);
	double xx=0,yy=0,nowT;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			xx+=cos((T[i]+T[j])/L*Pi)*(n-(j-i)*2),yy+=sin((T[i]+T[j])/L*Pi)*(n-(j-i)*2);
	xx*=6.0/n/(n-1)/(n-2);yy*=6.0/n/(n-1)/(n-2);
	printf("%.15lf %.15lf",xx,yy);
} 

Measured memory_bytes: 896
class UnionFind:
	def __init__(self, n):
		self.groups = [g for g in range(n)]

	def get_root(self, node):
		parent = self.groups[node]
		if parent == node:
			return parent
		else:
			root = parent
			parent = self.groups[parent]
			while root != parent:
				root = parent
				parent = self.groups[parent]
			
			while node != root:
				tmp = self.groups[node]
				self.groups[node] = root
				node = tmp
			
			return root
	
	def set_root(self, node, root):
		parent = self.groups[node]
		while parent != root:
			self.groups[node] = root
			node = parent
			parent = self.groups[node]
	
	def combine(self, i1, i2):
		self.set_root(i2, self.get_root(i1))
	
	def in_same_group(self, i1, i2):
		return self.get_root(i1) == self.get_root(i2)
	
	def to_counts(self):
		table = [None] * len(self.groups)
		for i in range(len(self.groups)):
			g = self.get_root(i)
			if table[g] != None:
				table[g] += 1
			else:
				table[g] = 1
		
		for i in range(len(self.groups)):
			table[i] = table[self.get_root(i)]
		
		return table

	def to_list_list(self):
		table = [[] for _ in range(len(self.groups))]
		for i in range(len(self.groups)):
			g = self.get_root(i)
			if table[g] != None:
				table[g].append(i)
			else:
				table[g] = [i]
		
		for i in range(len(self.groups)):
			table[i] = table[self.get_root(i)]
		
		return table
	
	def to_dic(self):
		table = {}
		for i in range(len(self.groups)):
			g = self.get_root(i)
			if g in table:
				table[g].append(i)
			else:
				table[g] = [i]
		return table
	
	def to_list(self):
		table = self.to_dic()
		return [table[g] for g in table]


N, M = map(int, input().split())

uf = UnionFind(N)

for _ in range(M):
	A, B = map(int, input().split())
	uf.combine(A - 1, B - 1)

print(max(uf.to_counts()))



Measured memory_bytes: 18620
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

inline int chToInt(char ch) {
    if (ch == 'R') {
        return 0;
    } else if (ch == 'G') {
        return 1;
    }
    return 2;
}

int main() {
    int N;
    string str;

    cin >> N;
    cin >> str;
    long long ans = 0;

    vector< vector <int> > preSum(N+1, vector<int>(3));

    for (int i = 0; i < N; ++i) {
        preSum[i+1] = preSum[i];
        ++preSum[i+1][chToInt(str[i])];
    }

    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            int num[3] = {chToInt(str[i]), chToInt(str[j])};

            if (num[0] != num[1]) {
                for (int k = 0; k < 3; ++k) {
                    if (k != num[0] && k != num[1]) {
                        num[2] = k;
                        break;
                    }
                }

                ans += (preSum[N][num[2]] - preSum[j][num[2]]);

                int diff = j-i;

                if (diff+j < N && chToInt(str[diff+j]) == num[2]) {
                    --ans;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

char N[4];

int main(){
     cin >> N[0] >> N[1] >> N[2] >> N[3];
     sort(N,N+4);
     if (!strcmp(N,"1479")) cout << "YES" << endl;
     else cout << "NO" << endl;
     return 0;
}



Measured memory_bytes: 256
from bisect import bisect_right
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0] * (n+1)
sb = [0] * (m+1)
for i in range(n):
    sa[i+1] = sa[i] + a[i]
for i in range(m):
    sb[i+1] = sb[i] + b[i]
ans = 0
for i in range(n+1):
    cnt_a = i
    rest = k - sa[i]
    if rest < 0:
        break
    cnt_b = bisect_right(sb, rest) - 1
    ans = max(ans, cnt_a+cnt_b)
print(ans)


Measured memory_bytes: 47540
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  string s; cin>>s;
  if(s[0]=='7' || s[1]=='7' || s[2]=='7'){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}


Measured memory_bytes: 3628
using System;
using System.Linq;

namespace ABC172
{
    class D
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var Count = new long[N + 10].Select(x => x = 1).ToArray();

            for (int i = 2; i <= N; i++)
            {
                var index = 1;
                while (i * index <= N)
                {
                    Count[i * index]++;
                    index++;
                }
            }

            var sum = 0L;
            for (int i = 1; i <= N; i++)
            {
                sum += Count[i] * i;
            }

            //Console.WriteLine(string.Join(" ", Count));
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 106956
N,M,X,Y = map(int,input().split())

x = list(map(int,input().split()))
y = list(map(int,input().split()))

mx = max(x)
my = min(y)

flag = False
for z in range(X+1,Y+1):
    if mx<z and z<=my:
        flag=True

if flag:
    print("No War")
else:
    print("War")


Measured memory_bytes: 38384
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

ll LCM(ll x, ll y) {
    return x / GCD(x, y) * y;
}

ll wazu = 1000000007;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (wazu - inv(wazu % x) * (wazu / x)) % wazu;
        if (a >= 0) { return a; }
        else { return wazu + a; }
    }
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    int N, M;
    cin >> N >> M;
    
    vector<string> A(N);
    vector<string> B(M);

    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];

    vector<vector<char> > P(N,vector<char>(N));
    vector<vector<char> > Q(M,vector<char>(M));

    rep(i, N) {
        rep(j, N) {
            P[i][j] = A[i][j];
        }
    }

    rep(i, M) {
        rep(j, M) {
            Q[i][j] = B[i][j];
        }
    }

    int kk = 0;

    rep(x, N - M + 1) {
        rep(y, N - M + 1) {
            int k = 0;
            rep(i, M) {
                rep(j, M) {
                    if (Q[i][j] == P[i + x][j + y]) { ++k; }
                }
            }
            if (k == M * M) {
                ++kk; }
        }
    }

    if (kk > 0) { cout << "Yes" << endl; }
    else { cout << "No" << endl; }

}

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

using namespace std;

#define FOR(i,a,b) for (int i = a; i < b; ++i)

#define MAX_N 100000
int arr[MAX_N];
unsigned long long dp[MAX_N];
int N,K;

int main() {
	cin >> N>>K;
	FOR(i,0,N) {
		cin >> arr[i];
		dp[i] = -1;
	}
	dp[0] = 0;
	FOR(i, 1, N) {
		dp[i] = ULLONG_MAX;
		FOR(j,1,K+1) if (i-j >= 0) dp[i] = min(dp[i], dp[i-j]+abs(arr[i]-arr[i-j]));
	}

	cout << dp[N-1] << "\n";
   
    return 0;
}

Measured memory_bytes: 1408
//============================================================================
// Name        : c.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<vector>
#include<algorithm>
typedef long long ll;
using namespace std;

int main() {
	ll n;cin>>n;
	vector<ll> a(n),ar(n),p,m,d(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>=0){
			p.push_back(a[i]);
		}else{
			m.push_back(-a[i]);
		}
	}
	int pn=n/2+n%2;
	int mn=n/2;
	sort(p.begin(),p.end());
	sort(m.begin(),m.end());
	sort(a.begin(),a.end());
	ll ans=0;
	for(int i=1;i<n-1;i++){
		if(a[i]>0){
			d[i]=1;
		}else{
			d[i]=0;
		}
	}
	d[0]=0;
	d[n-1]=1;
	for(int i=0;i<n;i++){
		if(d[i]){
			ans+=a[i];
		}else{
			ans-=a[i];
		}
	}
	cout<<ans<<endl;
	int temp=a[0];
	int j=n-2;
	while((j>0)*(d[j]==1)){
		cout<<temp<<' '<<a[j]<<endl;

		temp=temp-a[j];
		j--;
	}
	cout<<a[n-1]<<' '<<temp<<endl;
	j=1;
	temp=a[n-1]-temp;
	while((j<n-1)*(d[j]==0)){
		cout<<temp<<' '<<a[j]<<endl;
		temp=temp-a[j];
		j++;
	}
//	while(pn){
//		if(p.size()){
//			pn--;
//			ans+=p.back();
//			p.pop_back();
//		}else{
//			break;
//		}
//	}
//	while(mn){
//		if(m.size()){
//			mn--;
//			ans+=m.back();
//			m.pop_back();
//		}else{
//			break;
//		}
//	}
//	for(int i=0;i<n/2;i++){
//		ans+=a[n-1-i];
//		ans-=a[i];
//	}
//	int mul=1;
//	int flag=0;
//	if(n%2){
//		if(a[n/2]>0){
//		ans+=a[n/2];
//		}else{
//			ans-=a[n/2];
//			mul*=-1;
//			flag=1;
//
//		}
//	}
//	cout<<ans<<endl;
//	ans=0;
//
//	if(n%2){
//		mul*=-1;
//	}
//	if(mul==-1){
//		cout<<a[0]<<' '<<a[n-1]<<endl;
//		ans=a[0]-a[n-1];
//
//	}else{
//		cout<<a[n-1]<<' '<<a[0]<<endl;
//		ans=a[n-1]-a[0];
//	}
//	int fo=1;
//	int ba=n-2;
//	for(int i=0;i<n-2;i++){
//		if(mul==1){
//			cout<<a[fo]<<' '<<ans<<endl;
//			ans=a[fo]-ans;
//			if(flag){
//				cout<<ans<<' '<<a[fo]<<endl;
//				ans=ans-a[fo];
//			}
//			fo++;
//		}else{
//			cout<<a[ba]<<' '<<ans<<endl;
//
//			ans=a[ba]-ans;
//			ba--;
//		}
//		mul*=-1;
//	}
	return 0;
}


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

public class Main {
	public static void main(String[] args) throws IOException{
		String[] str;
		int m,f,r;
		String s;

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


		while(true){
			str = br.readLine().split(" ");
			m = Integer.parseInt(str[0]);
			f = Integer.parseInt(str[1]);
			r = Integer.parseInt(str[2]);
			if(m==-1&&f==-1&&r==-1)break;
			if(m==-1||f==-1){
				s="F";
			}else if(m + f < 30){
				s="F";
			}else if(m + f < 50){
				if(r >= 50){
					s="C";
				}else{
					s="D";
				}
			}else if(m + f < 65){
				s ="C";
			}else if(m + f < 80){
				s = "B";
			}else{
				s = "A";
			}
			System.out.println(s);
		}

		br.close();
	}
}

Measured memory_bytes: 24232
#include <stdio.h>

int main(void)
{
	int a,b,c,d,e;
	scanf("%d %d %d",&a,&b,&c);
	if(b>c){d=c;}
	else {d=b;}
	
	if(a<b+c)e=b+c-a;
	else e=0;
	
	printf("%d %d\n",d,e);
	
	return 0;
}

Measured memory_bytes: 128
import sys
def input(): return sys.stdin.readline().rstrip()
class UnionFind():
    def __init__(self, n):
        self.n=n
        self.parents=[-1]*n # 親(uf.find()で経路圧縮して根)の番号。根の場合は-(そのグループの要素数)
        self.member_color=[[0,0]for _ in range(n)] #.の数，#の数
        for i in range(n):
            if S[i//w][i%w]=="#": 
                self.member_color[i][1]=1
            else:
                self.member_color[i][0]=1
    def find(self,x):
        #グループの根を返す
        if self.parents[x]<0:return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    def unite(self,x,y):
        #要素x,yのグループを併合
        x,y=self.find(x),self.find(y)
        if x==y:return
        if self.parents[x]>self.parents[y]:#要素数の大きい方をxに
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x #要素数が大きい方に併合
        self.member_color[x][0]+=self.member_color[y][0]
        self.member_color[x][1]+=self.member_color[y][1] 
    def size(self,x):
        #xが属するグループの要素数
        return -self.parents[self.find(x)]
    def same(self,x,y):
        #xとyが同じグループ？
        return self.find(x)==self.find(y)
    def members(self,x):
        #xと同じグループに属する要素のリスト
        root=self.find(x)
        return [i for i in range(self.n) if self.find(i)==root]
    def roots(self):
        #全ての根の要素のリスト
        return [i for i, x in enumerate(self.parents) if x<0]
    def group_count(self):
        #グループの数
        return len(self.roots())
    def all_group_members(self):
        #各ルート要素のグループに含まれる要素のリストの辞書
        return {r: self.members(r) for r in self.roots()}
    def all_group_members_list(self):
        #各ルート要素のグループに含まれる要素のリストのリスト
        #[[0, 2], [1, 3, 4, 5]]
        return list(self.all_group_members().values())
    def __str__(self):
        #各ルート要素のグループに含まれる要素のリストをprint()
        return '\n'.join('{}: {}'.format(r,self.members(r)) for r in self.roots())
def main():
    global w,S
    h,w=map(int,input().split())
    S=[input() for _ in range(h)]
    uf=UnionFind(h*w)
    for i in range(h):
        for j in range(w):
            ss=S[i][j]
            for row,col in ((1,0),(-1,0),(0,1),(0,-1)):
                if i+row>=0 and i+row<h and j+col>=0 and j+col<w and ss!=S[i+row][j+col]:
                    uf.unite((i+row)*w+j+col,i*w+j) 
    ans=0
    for r in uf.roots():
        ans+=uf.member_color[r][0]*uf.member_color[r][1]
    print(ans)
if __name__=='__main__':
    main()

Measured memory_bytes: 73076
#include <stdio.h>
int main()
{
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    int res= x-y;
    int ans= z-res;
    if(ans>=0)
        printf("%d\n",ans);
    else
        printf("0\n");

    return 0;
}




Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

const ll inf = 1e18;

// dp[i][j] 下位i桁まで繰り上がりがjの状態の最小値
ll dp[1000010][2];

int main() {
    string s; cin >> s;
    reverse(s.begin(), s.end());
    s += '0';

    int len = s.size();
    rep(i,len+1) rep(j,2) dp[i][j] = inf;
    dp[0][0] = 0;

    rep(i,len) rep(j,2) {
        int d = s[i] - '0';
        d += j;
        chmin(dp[i+1][0], dp[i][j]+d);
        chmin(dp[i+1][1], dp[i][j]+(10-d));
    }
    cout << dp[len][0] << endl;
    return 0;
}

Measured memory_bytes: 17028
n = int(input())
a = list(map(int, input().split()))

def gcd(x, y):
	while y:
		x, y = y, x%y
	return x

def lcm(x,y):
	return (x * y) // gcd(x,y)

c = a[0]
for i in a:
	c = gcd(c,i)
print (c)


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int M = 1000000007;

int gcd(int a, int b) {
    while (b > 0) {
        int t = a % b;
        a = b;
        b = t;
    }
    return a;
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = h - 1; i >= 0; --i)
        cin >> s[i];

    int ans = 2;
    for (int i = 1; i <= h; ++i) {
        for (int j = 1; j <= w; ++j) {
            if (gcd(i, j) > 1) continue;
            int c = 0;
            for (int k = i - 1; k <= i && k < h; ++k) {
                for (int l = j - 1; l <= j && l < w; ++l) {
                    c += s[k][l] == '#';
                }
            }
            if (c == 0 || c == 4) continue;

            // up-right
            c = 0;
            for (int k = 0; k <= h; ++k) {
                int l = j * k / i;
                if (l < 0) continue;
                if (l >= w) break;
                if (k == 0)
                    c += s[k][l] == '#';
                else if (k == h)
                    c += s[k - 1][l] == '#';
                else
                    c += s[k - 1][l] != s[k][l];
            }
            for (int k = 0; k <= w; ++k) {
                int l = (i * k - 1) / j;
                if (l < 0) continue;
                if (l >= h) break;
                if (k == 0)
                    c += s[l][k] == '#';
                else if (k == w)
                    c += s[l][k - 1] == '#';
                else
                    c += s[l][k - 1] != s[l][k];
            }
            ans = max(ans, c / 2 + 1);

            // down-left
            c = 0;
            for (int k = 0; k <= h; ++k) {
                int l = (j * k - 1) / i;
                if (l < 0) continue;
                if (l >= w) break;
                if (k == 0)
                    c += s[k][l] == '#';
                else if (k == h)
                    c += s[k - 1][l] == '#';
                else
                    c += s[k - 1][l] != s[k][l];
            }
            for (int k = 0; k <= w; ++k) {
                int l = i * k / j;
                if (l < 0) continue;
                if (l >= h) break;
                if (k == 0)
                    c += s[l][k] == '#';
                else if (k == w)
                    c += s[l][k - 1] == '#';
                else
                    c += s[l][k - 1] != s[l][k];
            }
            ans = max(ans, c / 2 + 1);
        }
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3704