akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

int main(void){
	string s;
	ll k; cin >> s >> k;
	ll nokori = k;
	rep(i, s.size()){
		if(s[i] == 'a' && i != s.size() - 1) continue;
		
		if(i == s.size() - 1){
			// printf("%lld\n", nokori);
			nokori %= 26;
			ll d = (s[i] - 'a' + nokori) % 26;
			s[i] = 'a' + d;
		}else{
			ll d = 'z' - s[i] + 1;
			if(d <= nokori){
				nokori -= d;
				s[i] = 'a';
			}
		}
	}
	cout << s << endl;
}

Measured memory_bytes: 512
<?php
list($N, $K) = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));

$has_candy = [];
for ($i = 0; $i < $K; $i++) {
    $d_i = (int)fgets(STDIN);
    $A_j = array_map(function ($n) {
        return (int)$n;
    }, explode(' ', fgets(STDIN)));
    foreach ($A_j as $A_ij) {
        if (!in_array($A_ij, $has_candy)) {
            $has_candy[] = $A_ij;
        }
    }
}

echo $N - count($has_candy);


Measured memory_bytes: 16112
#include<iostream>
#include<string>
#define rep(i, n) for (int i = 1; i <= (n); i++)
using namespace std;

int main() {

    int h, w;
    cin >> h >> w;

    string board[55];
    rep (i, h) cin >> board[i];

    rep(i, h){
        rep(j, w){
            if(board[i][j] == '#' && board[i-1][j] != '#' && board[i+1][j] != '#' && board[i][j-1] != '#' && board[i][j+1] != '#'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	if s == "RRR" {
		fmt.Println(3)
	} else if s == "RRS" || s == "SRR" {
		fmt.Println(2)
	} else if s == "SSS" {
		fmt.Println(0)
	} else {
		fmt.Println(1)
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}


Measured memory_bytes: 1772
N,K = map(int,input().split())
P = list(map(int,input().split()))
for i in range(N):
    P[i] -= 1
C = list(map(int,input().split()))
ans = max(C)
for i in range(N):
    p = i
    d = []
    while True:
        p = P[p]
        d.append(C[p])
        if p == i:
            break
    #print(d,sum(d))
    val = 0
    for j in range(min(K,len(d))):
        val += d[j]
        ans = max(ans,val)
        #print(val,i,j)
    if K > len(d):
        val = val = (K//len(d)-1) * sum(d)
        k = K - (K//len(d)-1)*len(d)
        d += d
        ans = max(ans,val)
        for j in range(min(k,len(d))):
            val += d[j]
            ans = max(ans,val)


print(ans)


Measured memory_bytes: 89528
def main():
    s = input().split()
    ss = sorted(set(s), key = s.index)
    cnt = []
    ans = []

    for x in ss:
        c = 0
        for y in s:
            if x == y:
                c += 1
            else:
                pass
        else:
            cnt.append(c)

    cntcnt = sorted(cnt, reverse = True)
    hoge = cntcnt.count(cntcnt[0])

    for x in range(hoge):
        ans.append(ss[cnt.index(cntcnt[x])])


    lenc = []
    for x in range(len(ss)):
        lenc.append(len(ss[x]))

    lenclenc = sorted(lenc, reverse = True)
    fuga = lenclenc.count(lenclenc[0])

    for x in range(fuga):
        ans.append(ss[lenc.index(lenclenc[x])])

    for x in range(len(ans)):
        if x != len(ans) - 1:
            print(ans[x], end = " ")
        else:
            print(ans[x])


if __name__ == "__main__":
    main()

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

int main(){
	int A,B,X;
	scanf("%d%d%d",&A,&B,&X);
	int max_a = X / 1000 + (X % 1000 == 0 ? 0 : 1);
	
	int res = 1e9;
	// i : num of 1L
	for(int i = 0; i <= max_a; i++){
		int x = std::max(0,X - 1000 * i);
		int j = x / 500 + (x % 500 == 0 ? 0 : 1);
		res = std::min(res,i*A+j*B);
	}
	printf("%d\n",res);
	return 0;
}



Measured memory_bytes: 3228
using System.Linq;
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Diagnostics;
using System.Reflection.Metadata;
using System.Threading;

namespace AtCoder
{
    class Program
    {

        struct Point
        {
            public int x;
            public int y;

            public Point(int x, int y)
            {

                this.x = x;
                this.y = y;

            }

        }


        const int BiggestMod = 1000000007;

        public static void Main()
        {

            var args = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var n = args[0];
            var d = args[1] * args[1];
            var ans = 0;

            for (int i = 0; i < n; i++)
            {

                args = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
                if (Math.Abs(args[0] * args[0]) + Math.Abs(args[1] * args[1]) <= d)
                    ans++;

            }

            Console.WriteLine(ans);
        }

    }

}

Measured memory_bytes: 41340
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s1 = scan.next();
		String s2 = scan.next();
		if(s1.equals(s2.substring(0,s2.length()-1))) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 35528
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
const int max_n = 1e5;
const ll mod = 1e9+7;
void send(int a,int b,int c,int d){
  printf("%d %d %d %d\n",a,b,c,d);
}
int main(){
  int n,m;  cin >> n >> m;
  vector<ll> v(n);
  rep(i,0,n){
    cin >> v[i];
  }
  vector<ll> ans(n+1,0);
  rep(i,0,n){
    ans[i+1] = ans[i] + v[i];
  }
  sort(all(v));
  vector<P> p(m);
  rep(i,0,m){
    ll x,y; cin >> x >> y;
    p.pb(mp(y,x));
  }
  sort(all(p),greater<P>());
  int now = 0;
  ll sum = 0;
  rep(i,0,m){
    int st = i;
    rep(j,0,p[i].se){
      if(now>=n) break;
      if(p[i].fi>v[now]){
        v[now] = p[i].fi;
        now++;
      }else{
        break;
      }
    }
  }
  rep(i,0,n){
    sum += v[i];
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 6400
#include<bits/stdc++.h>
#define fast ios::base_sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define M 1000000007
#define pie 3.141592653589793238
using namespace std;


signed main(){
    int a,b;cin >> a>> b;
    if(a < b){
        for(int i=0;i<b;i++)
            cout << a;
    }
    else{
        for(int i=0;i<a;i++)
            cout << b;
    }
    return 0;
}

Measured memory_bytes: 256
N,D=map(int,input().split())
X=[]
count=0
for i in range(N):
  x=list(map(int,input().split()))
  X.append(x)
for i in range(N-1):
  for j in range(i+1,N):
    Y=0
    for k in range(D):
      Y+=(X[i][k]-X[j][k])**2
    for l in range(1,int(Y)+1):
      if l**2==Y:
        count+=1
      elif l**2>Y:
        break
print(count)

Measured memory_bytes: 3064
import math
a,b,h,m = map(int, input().split())

d=abs((h+(m/60)) * 30-6*m)
if d>180:
    d=d-180

th=math.radians((h+(m/60)) * 30)
tm=math.radians(6*m)

#sita=math.radians(d)
#ans=a**2+b**2-2*a*b*math.cos(sita)
ans=((a*math.cos(th)-b*math.cos(tm))**2+(a*math.sin(th)-b*math.sin(tm))**2)

ans2=math.sqrt(ans)
print(ans2)

Measured memory_bytes: 9516
#include <iostream>
#include <string>
#include <fstream>
#include <unordered_map>
#include <vector>
#include <numeric>
#include <algorithm>

int main() {
	int a, b, c;
	std::cin >> a >> b >> c;
	int z = 100 * a + 10 * b + c;
	if (z % 4 == 0)
		std::cout << "YES" << std::endl;
	else
		std::cout << "NO" << std::endl;
}


Measured memory_bytes: 256
using System;

public class Test
{
	public static void Main( )
	{

		int n = int.Parse( Console.ReadLine() );
		double[] x = Array.ConvertAll( Console.ReadLine().Split( ' ' ), double.Parse );
		double[] y = Array.ConvertAll( Console.ReadLine().Split( ' ' ), double.Parse );
		double Dxy = 0;
		double Dxy2 = 0;
		double Dxy3 = 0;
		double Dmax = 0;
		for( var i=0; i<n; i++ ) {		
			double t = Math.Abs( x[i]-y[i] );
			Dxy += t;
			Dxy2 += Math.Pow( t, 2 );
			Dxy3 += Math.Pow( t, 3 );
			Dmax = Math.Max( t, Dmax );
		}
		Console.WriteLine( Dxy );
		Console.WriteLine( Math.Sqrt( Dxy2 ) );
		Console.WriteLine( Math.Pow( Dxy3, 1/3.0 ) );
		Console.WriteLine( Dmax );
	}
}

Measured memory_bytes: 9448
fun main(args: Array<String>) {
    val N = readInputLine().toLong()
    
    for (h in LongRange(1L, 3500L)) {
        for (n in LongRange(h, 3500L)) {
            val numerator = -N * h * n
            val denominator = N * n + N * h - 4L * h * n
            if (denominator < 0L && numerator % denominator == 0L) {
                println("$h $n ${numerator / denominator}")
                return
            }
        }
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 31824
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val Array(a, o, b) = sc.nextLine.split(" ")
    if (o == "+") println(a.toInt + b.toInt)
    else println(a.toInt - b.toInt)
  }
}


Measured memory_bytes: 25528
# -*- coding: utf-8 -*-

str_1,str_2 = input().split()
str_1_count,str_2_count = input().split()
del_str = input()
if del_str == str_1:
    str_1_count = int(str_1_count) - 1
else:
    str_2_count = int(str_2_count) - 1

print(str(str_1_count) +" " + str(str_2_count))

Measured memory_bytes: 3060
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

std::vector<std::string> solve(int n, int k, const std::vector<int>& points)
{
  std::vector<std::string> result;
  for (int i = k; i < n; ++i) {
    result.push_back(
        points.at(i - k) < points.at(i)
        ? "Yes"
        : "No");
  }
  return result;
}

int main()
{
  int n, k;
  std::cin >> n >> k;
  std::vector<int> points(n);
  for (auto& p : points) {
    std::cin >> p;
  }

  std::cout << std::setprecision(20);
  const auto results = solve(n, k, points);
  for (const auto& s : results) {
    std::cout << s << std::endl;
  }
}


Measured memory_bytes: 12376
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  map<ll,ll> m;
  ll n,k;cin>>n>>k;
  ll a;
  rep(i,n){
    cin>>a;
    m[a]++;
  }
  vector<ll> v;
    
  reps(x,m){
    v.pb(x.se);
  }

  sort(all(v),greater<ll>());
  ll ans=0;
  FOR(i,k,v.size()){
    ans+=v[i];
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 14964
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  string s; cin>>s;
	rep(i,s.size()) cout<<'x';
	cout << endl;
  return 0;
}


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

ll cnt[30];

ll pow_2(ll x) {
  ll ret=1;
  for (int i=0; i<x; i++) {
    ret=ret*2%1000000007;
  }
  return ret;
}
    

int main() {
  string s;
  int n;
  cin>>n>>s;

  for (int i=0; i<n; i++) {
    cnt[s[i]-'a']++;
  }

  ll cnt2=0;
  ll ans=1;
  for (int i=0; i<26; i++) {
    if(cnt[i]==1) {
      cnt2++;
    }
    else if(cnt[i]>1) {
      ans*=1+cnt[i];
    }
    ans%=1000000007;
  }
  if (cnt2==n)
    cout<<pow_2(cnt2)-1<<endl;
  else
    cout<<pow_2(cnt2)*ans%1000000007-1<<endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main () {
  int N, K, C;
  cin >> N >> K >> C;
  string S;
  cin >> S;
  int L[K+1], R[K+1];
  int tmp = 1;
  for (int i = 0; i < N;) {
    if (tmp > K) {
      break;
    }
    if (S[i] == 'o') {
      L[tmp] = i+1;
      ++tmp;
      i += C+1;
    } else {
      ++i;
    }
  }
  tmp = K;
  for (int i = N-1; i >= 0;) {
    if (tmp <= 0) {
      break;
    }
    if (S[i] == 'o') {
      R[tmp] = i+1;
      --tmp;
      i -= C+1;
    } else {
      --i;
    }
  }
  for (int i = 1; i <= K; ++i) {
    // printf("L[%d] = %d\n", i, L[i]);
    // printf("R[%d] = %d\n", i, R[i]);
    if (L[i] == R[i]) {
      printf("%d\n", L[i]);
    }
  }
  return 0;
}

Measured memory_bytes: 3332
//#define NDEBUG

#pragma region cp_template

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

  using i32 = std::int32_t;
  using i64 = std::int64_t;
  using u32 = std::uint32_t;
  using u64 = std::uint64_t;
  using isize = std::ptrdiff_t;
  using usize = std::size_t;

  struct rep {
    struct itr {
      usize i;
      constexpr itr(const usize i) noexcept : i(i) {}
      void operator++() noexcept { ++i; }
      constexpr usize operator*() const noexcept { return i; }
      constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
    };
    const itr f, l;
    constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
    constexpr auto begin() const noexcept { return f; }
    constexpr auto end() const noexcept { return l; }
  };
  struct revrep {
    struct itr {
      usize i;
      constexpr itr(const usize i) noexcept : i(i) {}
      void operator++() noexcept { --i; }
      constexpr usize operator*() const noexcept { return i; }
      constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
    };
    const itr f, l;
    constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
    constexpr auto begin() const noexcept { return f; }
    constexpr auto end() const noexcept { return l; }
  };
  template <class T> auto md_vec(const usize n, const T& value) {
    return std::vector<T>(n, value);
  }
  template <class... Args> auto md_vec(const usize n, Args... args) {
    return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
  }
  template <class T> constexpr T difference(const T& a, const T& b) noexcept {
    return a < b ? b - a : a - b;
  }
  template <class T> void chmin(T& a, const T& b) noexcept {
    if (b < a)
      a = b;
  }
  template <class T> void chmax(T& a, const T& b) noexcept {
    if (a < b)
      a = b;
  }
  template <class F> class rec_lambda {
    F f;

  public:
    rec_lambda(F&& f) : f(std::move(f)) {}
    template <class... Args> auto operator()(Args&&... args) const {
      return f(*this, std::forward<Args>(args)...);
    }
  };
  template <class F> auto make_rec(F&& f) { return rec_lambda<F>(std::move(f)); }
  template <class T> T scan() {
    T ret;
    std::cin >> ret;
    return ret;
  }
  constexpr char eoln = '\n';
  template <class T> T ceildiv(const T& l, const T& r) {
    return l / r + (l % r != 0 ? 1 : 0);
  }

} // namespace n91

#pragma endregion cp_template

namespace n91 {

  void main_() {
    /*
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    //*/
    const usize n = scan<usize>();
    std::vector<u64> a(n);
    for (auto& e : a) {
      std::cin >> e;
    }
    std::vector<u64> dp(n + 1);
    dp[0] = 1000;
    for (const usize i : rep(0, n)) {
      dp[i + 1] = dp[i];
      for (const usize k : rep(0, i)) {
        chmax(dp[i + 1], a[i] * (dp[k] / a[k]) + dp[k] % a[k]);
      }
    }
    std::cout << dp[n] << eoln;
  }

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }

int main() {
    int a, b; cin >> a >> b;
    if(a < 6) {
        cout << 0 << endl;
    } else if(a < 13) {
        cout << b / 2 << endl;
    } else {
        cout << b << endl;
    }
    return 0;
}


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

using namespace std;
const int MOD=1e+5;
vector <int> a;
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int x,y;
    int p;
    cin >> p;
    while(p--)
    {
        cin >> x;
        if(x == 0)
        {
            cin >> y;
            a.push_back(y);
        }
        else if(x == 1)
        {
            cin >> y;
            cout << a[y] << '\n';
        }
        else a.pop_back();
    }
    return 0;
}




Measured memory_bytes: 5008
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
//	cut here before submit 
//	freopen ("testcase.MV", "r", stdin );
	string str = "";
	map<int,int> cnt; cnt.clear();
	int max_cnt = 0;
	while (getline (cin, str ) ){
		stringstream ss (str );
		int a;
		ss >> a;
		cnt[a]++;
		max_cnt = max (max_cnt, cnt[a] );
	} // end while
	vector<int> res; res.clear();
	map<int,int>::iterator it = cnt.begin();
	for (;it != cnt.end(); it++ ){
		int num = (*it).first;
		int c = (*it).second;
		if (max_cnt == c ){
			res.push_back (num );
		} // end if
	} // end for
	sort (ALL (res ) );
	rep (i, res.size() ){
		cout << res[i] << endl;
	} // end rep
		
	return 0;
}

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

// Given is a lowercase English letter C that is not z.Print the letter that follows C in alphabetical order.


int main() {
    int N, M;
    cin >> N >> M;
    int* problems = new int[N];
    for (int i = 0; i < N; ++i)
        problems[i] = 0;
    int prob;
    string acc;
    int totalpenalty = 0;
    int totalCorrect = 0;
    for (int i = 0; i < M; ++i) {
        cin >> prob >> acc;
        if (acc == "AC" && problems[prob-1] != -1) {
            totalpenalty += problems[prob-1];
            ++totalCorrect;
            problems[prob - 1] = -1;
        }
        else if(problems[prob-1] !=-1) {
            ++problems[prob-1];
        }
    }
    cout << totalCorrect << " " << totalpenalty;
}

Measured memory_bytes: 640
<?php

fscanf(STDIN, "%d %d %d", $h, $w, $K);

$dp = array_fill(0, $h, array_fill(0, $w, 0));
$dp[0][0] = 1;
const MOD = 1000000007;

for ($i = 0; $i < $h; ++$i) {
    for ($j = 0; $j < $w; ++$j) {
        for ($k = 0; $k < (1<<($w - 1)); ++$k) {
            // 横線は2のw-1乗本取りうる

            $ok = true;
            for ($l = 0; $l < ($w - 2); ++$l) {
                if (($k & (1<<$l)) && ($k & (1<<($l + 1)))) $ok = false;
            }

            if ($ok) {
/* echo "i: $i, j: $j, k: $k, ok: $ok", PHP_EOL; */
/* printf("%04b\n", $k); */

                if (($j >= 1) && ($k & (1<<($j - 1)))) {
                    $dp[$i + 1][$j - 1] += $dp[$i][$j];
                    $dp[$i + 1][$j - 1] %= MOD;
                } else if (($j <= $w - 2) && ($k & (1<<($j)))) {
                    $dp[$i + 1][$j + 1] += $dp[$i][$j];
                    $dp[$i + 1][$j + 1] %= MOD;
                } else {
                    $dp[$i + 1][$j] += $dp[$i][$j];
                    $dp[$i + 1][$j] %= MOD;
                }
            }
        }
    }
}
echo $dp[$h][$K - 1], PHP_EOL;


Measured memory_bytes: 16208
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){
    
    long long N,T[5],min,ans;

    min = DBL_MAX;

    cin >> N;
    for(int i=0;i<5;i++){
        cin >> T[i];
        if(T[i]<min){
            min = T[i];
        }
    }

    

    if(N<=min){
        ans=5;
    }else{
        ans = ((N+(min-1))/min) + 4;
    }

    cout << ans;

    return 0;
}


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

struct Data {
    int i;
    int a_i;
};

int main() {
    int n;
    std::cin >> n;

    std::vector<Data> data;
    data.reserve(n);

    for(int i = 0; i < n; ++i) {
        int a;
        std::cin >> a;
        data.push_back(Data { i + 1, a });
    }

    std::sort(data.begin(), data.end(), [](const Data d1, const Data d2) { return d1.a_i < d2.a_i; });

    for(const auto d: data) {
        std:: cout << d.i << " ";
    }

    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main() {
	int a, b, x;
	cin >> a >> b >> x;
	if (x - a >= 0 && x - a <= b)print("YES");
	else print("NO");




	return 0;
}

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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

ll lcn(ll a, ll b) {
	ll tmp;
	if(a<b){
		tmp = a;
		a = b;
		b = tmp;
	}

	ll r = a % b;
	while(r!=0){
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

int main() {
	ll a,b;
	cin >> a >> b;
	ll l = lcn(a,b);
	
	int end = int(sqrt(l))+1;
	// cout << "l,end: ";
	// cout << l << " " <<  end << endl;

	ll cnt = 1;
	FOR(i,2,end+1) {
		if (l%i == 0) {
			cnt++;
			l /= i;
		}
		while(l%i==0) {
			l /= i;
		}
	}
	if(l > end) {
		cnt += 1;
	}
	cout << cnt << endl;
}



Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
using namespace std;
const int N=1e5+11,mod=1e9+7;
int t,n,x,mx,sum;
char s[N];
int f[N][5][5][5];
int b[5][5][5][5];
inline void inc(int &x,int y){
	x+=y;
	if(x>=mod)
		x-=mod;
}
int main(){
	scanf("%d",&n);
	if(n==1){
		puts("4");
		return 0;
	}
	if(n==2){
		puts("16");
		return 0;
	}
	if(n==3){
		puts("61");
		return 0;
	}
	int ans=0;
	rep(i,1,4)
		b[i][1][3][2]=1,
		b[i][1][2][3]=1,
		b[i][3][1][2]=1;
	rep(i,1,4)
		b[1][3][i][2]=b[1][i][3][2]=1;
	rep(i,1,4)
		rep(j,1,4)
			rep(k,1,4)
				f[0][i][j][k]=1;
	
		f[0][1][3][2]=0,
		f[0][1][2][3]=0,
		f[0][3][1][2]=0;
	rep(i,1,n-3)
	rep(o,1,4)
		rep(j,1,4)
			rep(k,1,4)
				rep(l,1,4)
					if(!b[o][j][k][l])
						inc(f[i][j][k][l],f[i-1][o][j][k]);
	rep(i,1,4)
		rep(j,1,4)
			rep(k,1,4)
				inc(ans,f[n-3][i][j][k]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////////////////
int n;
double ans=0;
cin >> n;
double  v[n];
for(int i=0;i<n;i++){
   cin >> v[i];
}
sort(v,v+n);
for(int i=0;i<n;i++){
   ans += v[i]/pow(2,n-i);
}

ans = ans + v[0]/pow(2,n);
cout << ans << endl;


////////////////////////////////////////////////////////
return 0;}


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    if (A[0] != 0) {
        cout << -1 << endl;
        return 0;
    }
    ll ans = 0;
    for (int i = 1; i < N; i++) {
        if (A[i] > A[i-1] + 1) {
            cout << -1 << endl;
            return 0;
        }
    }
    for (int i = 0; i < N-1; i++) {
        if (A[i] + 1 == A[i+1]) continue;
        ans += A[i];
    }
    ans += A[N-1];
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

const LL MOD = 1000000007;
VL fact_memo(100005+1);

LL mod_pow_fast(LL a,LL n){
    LL p = a;
    LL ret = 1;
    while(n){
        if(n & 1) ret = (ret * p) % MOD;
        n = n >> 1;
        p = (p * p) % MOD;
    }
    return ret;
}
LL mod_inv(LL x){
    return mod_pow_fast(x, MOD - 2);
}
LL mod_fact(LL n){
    if(n <= 100005)return fact_memo[n];

    LL ret = 1;
    for(LL i = 2; i <= n; i++){
        ret = (ret * i) % MOD;
    }
    return ret;
}
LL mod_comb(LL n, LL r){
    // nCr = n! * inv(r!) * inv((n-r)!)
    return (((mod_fact(n) * mod_inv(mod_fact(r))) % MOD) *
                            mod_inv(mod_fact(n-r))) % MOD;
}

vector<VL> link(100005);

LL n,k;
LL ans = 0;

void f(LL node, LL depth, LL parent){
    LL sz = link[node].size();
    if(sz <= 1)return;
    if(k - 2 < sz - 1){
        ans = 0;
        return;
    }
    LL x = (mod_comb(k - 2, sz-1) * mod_fact(sz-1)) % MOD;
    ans = (ans * x) % MOD;
    REP(i,sz)if(link[node][i] != parent){
        f(link[node][i], depth+1, node);
    }
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>k;
    REP(i,n-1){
        LL a,b;
        cin>>a>>b;
        link[a].PB(b);
        link[b].PB(a);
    }
    fact_memo[0] = 1;
    FOR(i,1,100005+1){
        fact_memo[i] = (i * fact_memo[i-1]) % MOD;
    }
    ans = k;
    LL sz = link[1].size();
    if(k - 1 < sz){
        ans = 0;
    }
    LL x = (mod_comb(k - 1, sz) * mod_fact(sz)) % MOD;
    ans = (ans * x) % MOD;
    REP(i,sz){
        f(link[1][i], 2, 1);
    }
    PUTS(ans);
}

Measured memory_bytes: 12416
#include<cmath>
#include<cstdio>

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

using namespace std;

const double EPS=1e-9;

double dis2(double x,double y,double z){ return x*x+y*y+z*z; }

int main(){
	for(int n;scanf("%d",&n),n;){
		double sx[500],sy[500],sz[500];
		rep(i,n)	scanf("%lf%lf%lf",sx+i,sy+i,sz+i);
		int m;	scanf("%d",&m);
		double tx[50],ty[50],tz[50],phi[50];
		rep(i,m)	scanf("%lf%lf%lf%lf",tx+i,ty+i,tz+i,phi+i);

		int cnt=0;
		rep(i,n){
			bool looked=false;
			double a2=dis2(sx[i],sy[i],sz[i]);
			rep(j,m){
				double b2=dis2(tx[j],ty[j],tz[j]);
				double c2=dis2(sx[i]-tx[j],sy[i]-ty[j],sz[i]-tz[j]);
				double theta=acos((a2+b2-c2)/(2*sqrt(a2*b2)));	// law of cosines
				if(theta<phi[j]-EPS){ looked=true; break; }
			}
			cnt+=looked;
		}
		printf("%d\n",cnt);
	}

	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;
public class Main {
  public static void main(final String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int x = scan.nextInt();
    int t = scan.nextInt();
    int count = 0;
   
    while(n>0){
      n = n - x;
      count++;
    }
    System.out.println(t*count);
  }
}

Measured memory_bytes: 35604
from collections import defaultdict
from bisect import bisect_left
s = input()
t = input()
d = defaultdict(list)

ls = len(s)
cnt = 0

for ind,i in enumerate(s):
    d[i].append(ind)
        
if not set(s) >= set(t):
    print(-1)
else:
    now = -1
    for i in t:
        arr = d[i]
        y = (now+1) % ls
        ind = bisect_left(arr, y)
    
        if ind >= len(arr):
            now = now+1 + ls - y + arr[0]
            
        else:
            now = now+1 - y + arr[ind]
    print(now+1)

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

int main ()
{
  int a, b, c, d;
  cin>>a>>b>>c>>d;
  
  a+=b;
  c+=d;
  
  if(a==c)
  {
    cout<<"Balanced"<<endl;
  }
  else if(a<c)
  {
    cout<<"Right"<<endl;
  }
  else
  {
    cout<<"Left"<<endl;
  }
}

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

int main() {
    int n, x;
    cin >> n >> x;
    vector< int> in(n);
    for(int &e: in) cin >> e;
    sort(in.begin(), in.end());
    int res = 0;
    for(int e: in) {
        if(e <= x) {
            res++;
            x -= e;
        }
    }
    if(res == n and x > 0) res--;
    cout << res << endl;
}

Measured memory_bytes: 256
def solve():
    a,b=map(int,input().split())
    start=int(min(a*12.5,b*10))
    end=int(max((a+1)*12.5,(b+1)*10))

    for i in range(start, end):
        if (int(i * 0.08) == a and int(i * 0.1) == b):
            print(i)
            return
    print(-1)

solve()

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int i = Integer.parseInt(sa[0]);
		int o = Integer.parseInt(sa[1]);
		int j = Integer.parseInt(sa[3]);
		int l = Integer.parseInt(sa[4]);
		br.close();

		long ans = o;
		ans += i / 2 * 2;
		ans += j / 2 * 2;
		ans += l / 2 * 2;
		if (i > 0 && j > 0 && l > 0) {
			long ans2 = o + 3;
			i--;
			j--;
			l--;
			ans2 += i / 2 * 2;
			ans2 += j / 2 * 2;
			ans2 += l / 2 * 2;
			ans = Math.max(ans, ans2);
		}
		System.out.println(ans);
	}
}


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

namespace AtCoder.Contests.ABC166
{
    /// <summary>
    /// 
    /// </summary>
    static class E
    {
        static void Main(string[] args)
        {
            var n = NextInt();
            var aas = ReadIntArray();

            var api = new Dictionary<long, long>();
            long sum = 0;
            for (int i = 0; i < n; i++)
            {
                var a = aas[i];
                var maj = -a + i + 1;
                if (maj >= 0 && api.ContainsKey(maj)) sum += api[maj];

                if (api.ContainsKey(a + i + 1))
                {
                    api[a + i + 1]++;
                }
                else
                {
                    api[a + i + 1] = 1;
                }
            }

            Console.WriteLine(sum);
        }

        #region Console
        static int _index = 0;
        static string[] _buffer;

        static string Next()
        {
            if (_buffer == null || _index >= _buffer.Length)
            {
                _buffer = Console.ReadLine().Split();
                _index = 0;
            }

            return _buffer[_index++];
        }
        static int NextInt()
        {
            return int.Parse(Next());
        }
        static long NextLong()
        {
            return long.Parse(Next());
        }
        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        static int[] ReadIntArray(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadInt();
            }
            return a;
        }
        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        static long[] ReadLongArray(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLong();
            }
            return a;
        }
        static List<T> ReadObjects<T>(int n, Func<int[], T> creator)
        {
            var l = new List<T>(n);

            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                l.Add(creator(a));
            }

            return l;
        }

        static int[,] ReadMatrix(int n, int m)
        {
            var r = new int[n, m];
            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                for (int j = 0; j < m; j++)
                {
                    r[i, j] = a[j];
                }
            }
            return r;
        }
        #endregion
    }
}


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

def gcd(x, y):
    if x < y:
        x, y = y, x
    while y > 0:
        x, y = y, x % y
    return x

g = a[0]
for _a in a[1:]:
    g = gcd(g, _a)

print(g)

Measured memory_bytes: 14224
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>


using namespace std;

int main()
{
	for (int n, c = 1; scanf("%d", &n), n; ++c)
	{
		int p[32][32];
		int x, y;
		x = y = 0;
		bool upright = true;
		int z = 1;
		int dx, dy;
		dx = 1;
		dy = -1;
		while (z != n*n+1)
		{
			p[y][x] = z++;
			x += dx;
			y += dy;

			if (y == n)
			{
				y = n-1;
				x += 2;
				dx = 1;
				dy = -1;
			}
			else if (x == n)
			{
				x = n-1;
				y += 2;
				dx = -1;
				dy = 1;
			}
			else if (y == -1)
			{
				y = 0;
				dx = -1;
				dy = 1;
			}
			else if (x == -1)
			{
				x = 0;
				dx = 1;
				dy = -1;
			}
		}
		printf("Case %d:\n", c);
		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < n; ++j)
				printf("%3d", p[i][j]);
			printf("\n");
		}
	}

	return 0;
}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))

MOD = pow(10, 9)+7

def main():
    n, c = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    # 部分点
    # dp = [[0 for _ in range(c+1)] for _ in range(n+1)]
    # dp[0][0] = 1
    # for i in range(1, n+1):
    #     for j in range(c+1):
    #         for k in range(j+1):
    #             dp[i][j] += dp[i-1][j-k]*pow(a[i-1], k, MOD)
    #             if dp[i][j] >= MOD:
    #                 dp[i][j] -= MOD
    abc = [[0 for _ in range(401)] for _ in range(401)]
    # abc[i][j]: j**i
    for i in range(401):
        abc[0][i] = 1
    abc[0][0] = 0
    for i in range(1, 401):
        for j in range(1, 401):
            abc[j][i] = abc[j-1][i] * i % MOD
    
    for i in range(1, 401):
        for j in range(401):
            abc[j][i] += abc[j][i-1]
            if abc[j][i] >= MOD:
                abc[j][i] -= MOD
    
    dp = [[0 for _ in range(c+1)] for _ in range(n+1)]
    dp[0][0] = 1
    for i in range(1, n+1):
        for j in range(c+1):
            for k in range(j+1):
                accm = abc[k][b[i-1]] - abc[k][a[i-1]-1]
                if accm < 0:
                    accm += MOD
                dp[i][j] += dp[i-1][j-k] * accm % MOD
                if dp[i][j] >= MOD:
                    dp[i][j] -= MOD
    
    print(dp[n][c])


if __name__ == '__main__':
    main()


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

signed main(){

	lli n;
	lli k;
	cin>>n>>k;

	string s;
	cin>>s;

	lli cnt=0;
	REP(i,0,n){
		if(s.at(i)=='L'){
			if(i==0)continue;
			if(s.at(i-1)=='L')cnt++;
		}
		else{
			if(i==n-1)continue;
			if(s.at(i+1)=='R')cnt++;
		}
	}

	cout<<min((n-1),cnt+2*k)<<endl;

	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

struct union_find {
    vector<int> par;
    vector<int> rank;
    vector<int> siz;

    union_find(int n) : par(n), rank(n), siz(n) {
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }

    void init(int n) {
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = root(par[x]);
        }
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;

        if (rank[x] < rank[y]) {
            par[x] = y;
            siz[y] += siz[x];
        } else {
            par[y] = x;
            siz[x] += siz[y];
            if (rank[x] == rank[y]) rank[x]++;
        }
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x) {
        return siz[root(x)];
    }
};

int main(){
    int n, k, l;
    cin >> n >> k >> l;
    union_find a(n), b(n);
    int p, q, r, s;
    for (int i = 0; i < k; ++i) {
        cin >> p >> q;
        p--; q--;
        a.unite(p, q);
    }
    for (int i = 0; i < l; ++i) {
        cin >> r >> s;
        r--; s--;
        b.unite(r, s);
    }

    map<pii, int> mp;
    for (int i = 0; i < n; ++i) {
        mp[pii(a.root(i), b.root(i))]++;
    }

    for (int i = 0; i < n-1; ++i) {
        cout << mp[pii(a.root(i), b.root(i))] << " ";
    }
    cout << mp[pii(a.root(n-1), b.root(n-1))] << endl;
}

Measured memory_bytes: 16640
main()
{
  int n,i,a[10],b[10],h,g,c,x;
  for(scanf("%d",&n);n--;)
    {
      a[0]=b[0]=h=g=0;
      for(i=x=0;i<10;i++)
	{
	  scanf("%d",&c);
	  if(x!=0)continue;
	  if(a[h]>=c && b[g]>=c)
	    x=-1;
	  else
	    {
	      if(a[h]<c && (a[h]>b[g] || b[g]>=c))
		h++,a[h]=c;
	      else
		g++,b[g]=c;

	    }
	}
      puts(x?"NO":"YES");
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include<iostream>
#include<fstream>
#define ll long long
using namespace std;

int main(){
    string S;  cin >> S;
    int N = S.length();
    vector<int> cnt(3,0);
    for(int i=0; i<N; i++) cnt[S[i]-'a']++;
    sort(cnt.begin(), cnt.end());
    if(cnt[2] - cnt[0] >= 2){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <memory>
#include <functional>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i <= n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long LL;
typedef long long int LLI;

int solve(int cnt ,int sum,int now);
 int n=0,s=0;
int main(void)
{
     for(;;){
         cin >> n >> s;
        
        int ans = solve(0, 0, 0);  
         if(n == 0 && s == 0)break;
        cout << ans << endl;
        }
    return 0;  
}
int solve(int cnt ,int sum,int now)
{
    if(cnt == 10){
        return sum == s && now == n;
    }
    int res1 = solve(cnt+1,sum+cnt,now+1) ;
    int res2 = solve(cnt+1,sum,now);
    return res1+res2;
}

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

using namespace std;

typedef long long ll;

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

    int n;
    cin >> n;

    map<string,int> msi;
    int big = 0;
    
    string x;
    while(n--){
        cin >> x;
        msi[x]++;
        big = max(big, msi[x]);
    }

    vector<string> vs;
    for(auto y : msi){
        if(y.second == big) vs.push_back(y.first);
    }

    sort(vs.begin(), vs.end());

    for(string y : vs) cout << y << "\n";

    return 0;
}

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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

int main()
{
    ll x,y;
    cin>>x>>y;
    ll a=(3*x)+y;
    ll ans=a/2;
    cout<<ans<<endl;
    return 0;
}


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

int main(){
    int x1,x2,y1,y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int x = x2 - x1;
    int y = y2 - y1;

    printf("%d %d %d %d\n",x2 - y,y2 + x,x1 - y,y1 + x);
    return 0;
}

Measured memory_bytes: 256
import math


def inputIntList():
  return [int(s) for s in input().split()]


def inputInt():
  return int(input())


inf = float('inf')


def main():
  H, N = inputIntList()
  AB = [inputIntList() for _ in range(N)]
  dp = [inf for _ in range(H + 1)]

  dp[0] = 0
  for (a, m) in AB:
    for h in range(H):
      nxt = min(H, h+a)
      dp[nxt] = min(dp[h]+m, dp[nxt])
  # print(dp)
  return dp[H]


if __name__ == "__main__":
  print(main())


Measured memory_bytes: 48092
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
using namespace std;

ll mod = 1E9+7;

int main() {
    string K; cin >> K;
    int L = K.length();
    int D; cin >> D;

    ll dp[L+1][D][2];
    REP(i, L+1) REP(d, D) REP(k, 2) dp[i][d][k] = 0;
    dp[0][0][0] = 1;
    REP(l, L) REP(d, D) REP(isless, 2){
        int num = K[l] - '0';
        REP(next, 10){
            if (next < num) dp[l+1][(d+next)%D][1] += dp[l][d][isless];
            else if (next == num) dp[l+1][(d+next)%D][isless] += dp[l][d][isless];
            else{
                if (isless) dp[l+1][(d+next)%D][isless] += dp[l][d][isless];
            }
            dp[l+1][(d+next)%D][0] %= mod;
            dp[l+1][(d+next)%D][1] %= mod;
        }
    }
    ll ans = (dp[L][0][1] + dp[L][0][0] -1) % mod;
    if (ans < 0) ans += mod;
    cout << ans << endl;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  vector<int>B(N);
  B=A;
  sort(B.begin(),B.end());
  
  for(int i=0;i<N;i++){
    
    if(A.at(i) == B.at(N-1)){
      cout << B.at(N-2) <<endl;
    }
    else{
      cout << B.at(N-1)<<endl;}
    }
  }



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

using namespace std;
typedef long long ll;


int main(){
 long long a,b,c,d;
cin>>a>>b>>c>>d;

if(d%2==0)
{a-=b;
cout<<a;
}
else{
        b-=a;
    cout<<b;
}

return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
const ll mod = 1000000007;

int n, k;
string s;
int ans, happy;
signed main() {
    cin >> n >> k >> s;

    char temp = s[0];
    int cnt = 0;
    for (int i=0;i<n;i++) {
        if (temp != s[i]) cnt++;
        temp = s[i];
    }

    // 集計
    temp = s[0];
    for (int i=1;i<n;i++) {
        if(temp == s[i]) happy++;
        temp = s[i];
    }
    if (k >= cnt+1) cout << n-1 << endl;
    else if(s[0] == s.back()) {
        cout << min(happy + 2*k, n-1) << endl;
    } else {
        if (((cnt/2) +1) == k) cout << n-1 << endl;
        else cout << min(happy + 2*k, n-1) << endl;
    }
}

Measured memory_bytes: 512