akhauriyash/Code-Regression huggingface dataset:
package main

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

func main() {
	io, flush := NewIO()
	defer flush()

	n := io.ScanInt()
	judges := io.ScanStrings(n)
	judgeMap := map[string]int{}
	for _, j := range judges {
		judgeMap[j]++
	}
	fmt.Println("AC x", judgeMap["AC"])
	fmt.Println("WA x", judgeMap["WA"])
	fmt.Println("TLE x", judgeMap["TLE"])
	fmt.Println("RE x", judgeMap["RE"])
}

type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func NewIO() (*IO, func()) {
	io := &IO{
		scanner: newScanner(),
		writer:  newWriter(),
	}
	return io, func() { io.writer.Flush() }
}

func newScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 10000000), 10000000)
	s.Split(bufio.ScanWords)
	return s
}

func newWriter() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

func (io *IO) ScanBytes() []byte {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Bytes()
}

func (io *IO) ScanString() string {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Text()
}

func (io *IO) ScanStrings(n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		strs[i] = io.ScanString()
	}
	return strs
}

func (io *IO) Scan2DStrings(y, x int) [][]string {
	strings := make([][]string, y)
	for i := 0; i < y; i++ {
		strings[i] = io.ScanStrings(x)
	}
	return strings
}

func (io *IO) Scan2DGraph(y int) [][]string {
	strs := make([][]string, y)
	for i := 0; i < y; i++ {
		strs[i] = strings.Split(io.ScanString(), "")
	}
	return strs
}

func (io *IO) ScanInt() int {
	return int(io.ScanInt64())
}

func (io *IO) ScanInt2() (int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt3() (int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt4() (int, int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = io.ScanInt()
	}
	return ints
}

func (io *IO) Scan2DInts(y, x int) [][]int {
	ints := make([][]int, y)
	for i := 0; i < y; i++ {
		ints[i] = io.ScanInts(x)
	}
	return ints
}

func (io *IO) ScanInt64() int64 {
	i, err := strconv.ParseInt(io.ScanString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *IO) ScanFloat64() float64 {
	i, _ := strconv.ParseFloat(io.ScanString(), 64)
	return i
}

func (io *IO) ScanFloat64s(n int) []float64 {
	floats := make([]float64, n)
	for i := 0; i < n; i++ {
		floats[i] = io.ScanFloat64()
	}
	return floats
}

func (io *IO) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  int h, n;
  cin >> h >> n;
  int s = 0;
  REP(i, n) {
	int a;
	cin >> a;
	s += a;
  }
  if (h <= s) {
	  cout << "Yes" << endl;
	} else {
	  cout << "No" << endl;
	}
  return 0;
}


Measured memory_bytes: 256
menu=[]
menu.append(int(input()))
menu.append(int(input()))
menu.append(int(input()))
menu.append(int(input()))
menu.append(int(input()))

ans=0
for i in range(5):
  ans+=max((((menu[i]-1)//10)+1)*10,10)

tmp=[]
for i in range(5):
  s=str(menu[i])
  tmp.append(int(s[-1]))
tmp.sort()

hiku=0
for i in range(5):
  if not tmp[i]==0:
    hiku=tmp[i]
    break
    
if not hiku==0:
  ans = ans-(10-hiku)
  
print(ans)



Measured memory_bytes: 3064
#include<stdio.h>
#define MAX 1000

int n;
int A[MAX][MAX];

int main(){
  int i, j;
  int id, k, R;

  scanf("%d", &n);

  /*//初期化開始!
  for(i = 1; i <= n; i++){
    for(j = 1; j <= n; j++){
      A[i][j] = 0;
    }
    }*/
  
  for(i = 0; i < n; i++){
    scanf("%d %d", &id, &k);
    for(j = 0; j < k; j++){
      scanf("%d", &R);
      A[id][R] = 1;
    }
  }

  for(i = 1; i <= n; i++){
    for(j = 1; j <= n; j++){
      printf("%d", A[i][j]);
      if(j < n) printf(" ");
    }
    printf("\n");
  }
  
  return 0;
}



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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// DON'T USE THESE MACROS DURING ICPC PRACTICE
#define For(i,n) for (int i=0; i<n; i++)
#define FOR(i,a,b) for (int i=a; i<=b; i++)
#define Down(i,n) for (int i=n-1; i>=0; i--)
#define DOWN(i,a,b) for (int i=b; i>=a; i--)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef complex<ld> pt;
typedef vector<pt> pol;
typedef vector<int> vi;

const char nl = '\n';
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9+7;
const ld EPS = 1e-10;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());



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

	int n;
	cin >> n;

	int h[n], a[n];
	For(i,n) {
		cin >> h[i];
	}
	For(i,n) {
		cin >> a[i];
	}

	map<int,ll> lis;
	lis[INF] = INFLL;
	For(i,n) {
		auto it = lis.upper_bound(h[i]);
		int len = a[i];
		while (it->second <= a[i]) {
			a[i] -= it->second;
			it = lis.erase(it);
		}
		if (a[i] > 0) {
			it->second -= a[i];
		}
		lis[h[i]] = len;
	}

	ll ans = 0;
	for (const pair<int,ll>& it : lis) {
		if (it.first != INF) ans += it.second;
	}
	cout << ans << nl;

	return 0;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 10000
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_H = 310;
const int MAX_W = 310;

const int MAX_T = MAX_H*2;

int H, W;
char Field[MAX_H][MAX_W];

int T_Field[MAX_T][MAX_T];
int T_Sum[MAX_T][MAX_T];
int T_SumW[MAX_T][MAX_T];
int T_SumH[MAX_T][MAX_T];

int getT(int sx, int sy, int gx, int gy) {
  return T_Sum[gy][gx] - T_Sum[gy][sx] - T_Sum[sy][gx] + T_Sum[sy][sx];
}

signed main() {
  cin >> H >> W;
  REP(y,H) {
    REP(x,W) {
      cin >> Field[y][x];
      if(Field[y][x] == '#') {
        T_Field[x+y+2][y-x+MAX_W] = T_SumH[x+y+2][y-x+MAX_W] = T_SumW[x+y+2][y-x+MAX_W] =1;
      }
    }
  }

  REP(y,MAX_T-1) {
    REP(x,MAX_T-1) {
      T_SumH[y+1][x] += T_SumH[y][x];
      T_SumW[y][x+1] += T_SumW[y][x];
    }
  }

  REP(y,MAX_T-1) {
    REP(x,MAX_T-1) {
      T_Sum[y+1][x+1] = T_Sum[y+1][x] + T_Sum[y][x+1] - T_Sum[y][x] + T_Field[y][x];
    }
  }

  int ans = 0;
  REP(y,MAX_T) {
    REP(x,MAX_T) {
      if(T_Field[y][x] == 0) {
        continue;
      }
      FOR(nx,x+1,MAX_T) {
        int d = nx - x;
        if(T_Field[y][nx] == 0) {
          continue;
        }
        if(0 <= y-d) {
          ans += T_SumW[y-d][nx] - T_SumW[y-d][x-1];
          // ans += getT(x,y-d,nx+1,y-d+1);
        }
        if(y+d < MAX_T) {
          ans += T_SumW[y+d][nx] - T_SumW[y+d][x-1];
          // ans += getT(x,y+d,nx+1,y+d+1);
        }
      }
      FOR(ny,y+1,MAX_T) {
        int d = ny - y;
        if(T_Field[ny][x] == 0) {
          continue;
        }
        if(0 <= x-d) {
          ans += T_SumH[ny-1][x-d] - T_SumH[y][x-d];
          // ans += getT(x-d, y+1, x-d+1, ny);
        }
        if(x+d < MAX_T) {
          ans += T_SumH[ny-1][x+d] - T_SumH[y][x+d];
          // ans += getT(x+d, y+1, x+d+1, ny);
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
typedef long long ll;
ll dp[N],sum[N],a[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        if(i==1)
            sum[i]=a[i];
        else
            sum[i]=sum[i-2]+a[i];
    }
    for(int i=2;i<=n;i++)
    {
        if(i&1)
            dp[i]=max(dp[i-1],dp[i-2]+a[i]);
        else
            dp[i]=max(dp[i-2]+a[i],sum[i-1]);
    }
    printf("%lld\n",dp[n]);
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

int n, c[1500][1500], dp[1500][1500], l[1500], r[1500];
signed main(void)
{
  int H, W;
  cin >> H >> W;
  REP(i, H) REP(j, W) cin >> c[i][j];

  REP(i, H) REP(j, W) {
    if(c[i][j]) dp[i][j] = 0;
    else {
      if(!i) dp[i][j] = 1;
      else dp[i][j] = dp[i-1][j] + 1;
    }
  }
  ll ret = 0;
  REP(j, H) {
    stack<int> st;
    REP(i, W) {
      while(st.size() && dp[j][st.top()] >= dp[j][i]) st.pop();
      if(!st.size()) l[i] = i;
      else l[i] = i-st.top()-1;
      st.push(i);
    }
    while(st.size()) st.pop();
    for(int i=W-1; i>=0; --i) {
      while(st.size() && dp[j][st.top()] >= dp[j][i]) st.pop();
      if(!st.size()) r[i] = W-i-1;
      else r[i] = st.top()-i-1;
      st.push(i);
    }
    REP(i, W) ret = max(ret, (ll)dp[j][i]*(r[i]+l[i]+1));
  }
  cout << ret << endl;
  return 0;
}

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

const int kMaxNumItems = 100;
const int kMaxSumValues = 100000;

int kWeight[kMaxNumItems], kValue[kMaxNumItems];
int64_t kDP[kMaxSumValues + 1];

int main() {
  int num_items, weight_limit;
  cin >> num_items >> weight_limit;

  for (int i = 0; i < num_items; i++) {
    cin >> kWeight[i] >> kValue[i];
  }

  const int64_t kInf = (1LL << 50);
  fill(begin(kDP), end(kDP), kInf);
  kDP[0] = 0;

  int ans = 0;
  for (int i = 0; i < num_items; i++) {
    for (int sum_values = kMaxSumValues; sum_values >= 0; sum_values--) {
      if (sum_values - kValue[i] >= 0) {
        kDP[sum_values] = min(kDP[sum_values], kDP[sum_values - kValue[i]] + kWeight[i]);
      }

      if (kDP[sum_values] <= weight_limit) {
        ans = max(ans, sum_values);
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int a[N],n;
long long ans;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)scanf("%d",&a[i]);
	a[0]=-1;
	for (int i=1;i<=n;i++)
		if (a[i-1]<a[i]-1){
			puts("-1");
			return 0;
		}	
	for (int i=n;i;i--){
		if (a[i]==a[i+1]-1)continue;
		ans+=a[i];
	}	
	printf("%lld\n",ans);
}

Measured memory_bytes: 1024
import math
n = int(input())
if n < 6:
  print([0,1,2,3,4,5][n])
  quit()
ans = 10**6
m = int(math.log(n)/math.log(6))
for i in range(int(n/(6**m))+1):
  for j in range(6**m):
    s = i*(6**m)
    cnt = i
    lst = []
    for k in range(m):
      time = (j//(6**k)) % 6
      cnt += time
      s += time*(6**k)
      lst.append(time)
    if s <= n:
      N = n - s
      for k in range(6):
        cnt += (N//(9**k)) % 9
      ans = min(cnt,ans)
print(ans)

Measured memory_bytes: 44252
/*  ex3_2: Therefore
    Jun_JPN */

#include <stdio.h>

int main(void){

    int num, r;

    scanf("%d", &num);

    r = num % 10;   // 入力numを10で割った余り（numの1桁目数字）をrに代入

    switch (r){ // 剰余rの値によって場合分け
        case 2: case 4: case 5: case 7: case 9:
            printf("hon\n");
            break;
        
        case 0: case 1: case 6: case 8:
            printf("pon\n");
            break;
        
        case 3:
            printf("bon\n");
            break;
    }

    return 0;
}

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

using ll = long long;
#define REP(i, n) for(int (i)=0; (i)< (n); ++i)
#define REPR(i, n) for(int (i)=(n); (i)>=0; --i)
#define FOR(i, n, m) for(int (i)=(n); (i)<(m); ++i)
#define INF 1e9
//constexpr ll INF = 1LL << 62;
constexpr int mod = 1e9+7;

int N, M;
vector<vector<pair<int, int>>> g;
vector<int> pos;
vector<bool> homon;
bool ans = true;
void dfs(int x){
  for(auto e : g[x]){
    int nx = e.first, nc = e.second;
    if(!homon[nx]){
      pos[nx] = pos[x] + nc;
      homon[nx] = true;
      dfs(nx);
    }
    else if(pos[nx] != pos[x] + nc){
      ans = false;
//      cout << "nx:" << nx+1 << " pos[nx]:" << pos[nx] << " x:" << x+1 << " pos[x]:" << pos[x] << " nc:" << nc << " cost:" << pos[x] + nc << endl;
    }
  }
}
int main(){
  cin >> N >> M;
  g.resize(N);
  REP(i, M){
    int L, R, D;
    cin >> L >> R >> D;
    L--, R--;
    g[L].push_back({R, D});
    g[R].push_back({L, -D});
  }
  pos.resize(N);
  homon.resize(N, false);
  REP(i, N){
    if(!homon[i]){
      pos[i] = 0;
      homon[i] = true;
      dfs(i);
    }
  }
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 12032
n = int(raw_input())
a = map(int, raw_input().split())

count = 0
def merge(A, left, right, mid):
    L = [A[i] for i in range(left, mid)]
    R = [A[i] for i in range(mid, right)]
    L.append(10**9+1)
    R.append(10**9+1)
    i = 0
    j = 0
    global count
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
            count += mid - left - i
    
def mergeSort(A, left, right):
    if right > left + 1:
        mid = int((right + left) / 2)
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, right, mid)
        

mergeSort(a, 0, n)
print count

Measured memory_bytes: 23608
#include<iostream>
#include<math.h>
#include<cmath>
using namespace std;
typedef long long ll;
ll inf = 1000000000;
typedef pair<ll, ll> P;
int main() {
	ll n, k;
	cin >> n >> k;
	ll x = n % k;
	if (k - x > x) {
		cout << x << endl;
	}
	else {
		cout << k - x << endl;
	}
	return 0;
}

Measured memory_bytes: 256
a,b,c,d=map(int,input().split())
x=c-a
y=d-b
ans1=x*"R"+y*"U"
ans2=x*"L"+y*"D"
ans3="D"+(1+x)*"R"+(1+y)*"U"+"L"
ans4="U"+(1+x)*"L"+(1+y)*"D"+"R"
ans=ans1+ans2+ans3+ans4
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n;
    cin>>n;
    
    if((n>=105)&&(n<=134)){
        cout<<1<<endl;
    }
    if((n>=135)&&(n<=164)){
        cout<<2<<endl;
    }
    if((n>=165)&&(n<=188)){
        cout<<3<<endl;
    }
    if((n>=189)&&(n<=194)){
        cout<<4<<endl;
    }
    if(n>=195){
        cout<<5<<endl;
    }
    if(n<=104){
        cout<<0<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


ll llmax(ll x, ll y){
	if (x > y) return x;
	return y;
}


int main(){
	int x, y;
	cin >> x >> y;
	cout << x + y/2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define ll long long int
#define ld long double
#define vi vector<int>
#define vll vector<long long int>
#define fi first
#define se second
#define sc(n) scanf("%d",&n);
#define scll(n) scanf("%lld",&n);
#define scld(n) scanf("%Lf",&n);
#define scr(s) {char temp[1000000];scanf("%s",temp);s = temp;}
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" :" <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cout<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}


using namespace std;

int main()
{
  __;
  int n,k;
  cin>>n>>k;
  int*h = new int[n];
  for(int i=0;i<n;i++) cin>>h[i];
  vector<int> dp(n);
  // dp[1] = abs(h[1]-h[0]);
  dp[0] = 0;
  for(int i=1;i<n;i++)
  {
    dp[i] = INF;
    for(int j=1;j<=min(k,i);j++)
    {
      dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
    }
    // t(i,dp[i]);
    // dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
  }
  cout<<dp[n-1]<<endl;
  return 0;
}



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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  long long a;
  double b;
  cin >> a >> b;
  
  long long c = (long long) (b * 100 + 0.5);
  
  cout << a * c / 100 << '\n';
}

Measured memory_bytes: 3756
import string
 
count = {x: 0 for x in string.ascii_lowercase}
lines = ""
 
while True:
    try:
        lines += input().lower()
    except EOFError:
        break
         
for c in lines:
    if 'a' <= c <= 'z':
        count[c] += 1
         
for key in string.ascii_lowercase:
    print("{0} : {1}".format(key, count[key]))

Measured memory_bytes: 8096
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }
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 main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll X,Y,Z;
    cin >> X >> Y >> Z;
    swap(X, Y);
    swap(X, Z);
    cout << X << " " << Y << "  " << Z << endl;

    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i, n, p, a[200005]={0};
    cin>>n;
    for(i=1;i<n;i++)
    {
        cin>>p;
        a[p]++;
    }
    for(i=1;i<=n;i++)
    {
        cout<<a[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 4380
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val aa = readLine()!!.split(" ").map { it.toInt() }

    var cnt = 0L
    var prev = 0

    for (i in 0 until n) {
        if (prev > aa[i]) {
            cnt += prev - aa[i]
        } else {
            prev = aa[i]
        }
    }

    println(cnt)
}

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

int main()
{
    int K;
    cin >> K;
    vector<int> ans{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << ans[K - 1] << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <vector>

int main() {
  int N, M;
  scanf("%d %d", &N, &M);

  std::vector<int> D(N), C(M);

  for (int i=0; i<N; ++i)
    scanf("%d", &D[i]);

  for (int j=0; j<M; ++j)
    scanf("%d", &C[j]);

  int INF=1<<29;
  std::vector<std::vector<int>> dp(N+1, std::vector<int>(M+1, INF));
  dp[0][0] = 0;
  for (int j=0; j<M; ++j) {
    for (int i=0; i<N; ++i) {
      // dp[i][j]: jテヲツ猟・テァツ崢ョテッツシツ?nclusiveテッツシツ嘉」ツ?ォテゥツδステ・ツクツＪテ」ツ?ォテ」ツ??」ツ?淌」ツ??

      // stay
      dp[i][j+1] = std::min(dp[i][j+1], dp[i][j]);

      // go away
      dp[i+1][j+1] = std::min(dp[i+1][j+1], dp[i][j]+C[j]*D[i]);
    }
  }

  printf("%d\n", *std::min_element(dp[N].begin(), dp[N].end()));
  return 0;
}

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

int main() {
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    vector<int> p = {a, b, c, d, e};
    int ans = 1001001001;
    do {
        int time = 0;
        for (int i = 0; i < 4; ++i) {
            time += p[i];
            while (time % 10 != 0) time++;
        }
        time += p[4];
        ans = min(ans, time);
    } while (next_permutation(p.begin(), p.end()));
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
using ll = long long;

int main()
{
    ll x, y;
    cin >> x >> y;
    ll ans = 1001001001;
    if(y > x){
        ans = min(ans, abs(y-x));
    }
    ans = min(ans, abs(x+y) + 1); // +1 means reverse
    ans = min(ans, abs(x-y) + 2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	double n;
	while(scanf("%lf",&n),n>=0) {
		double x=(1<<7);
		char d[15];
		int idx=0;
		for(int i=7;i>=-4;i--) {
			if(i==-1) d[idx++]='.';
			if(n>=x) {
				n-=x;
				d[idx++]='1';
			}else {
				d[idx++]='0';
			}
			x/=2.0;
		}
		d[idx]='\0';
		if(n!=0) printf("NA\n"); else printf("%s\n",d);
	}
}

Measured memory_bytes: 1044
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXMASK=(1<<15);
const int MAXN=20;
const int mod=1e9+7;
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
int f[MAXMASK][3];
int n,m,nx[MAXN],bin[MAXN],ct[MAXMASK];
int tot[MAXN],ln;
int main()
{
	bin[1]=1;for(int i=2;i<20;i++)bin[i]=bin[i-1]<<1;
	n=read();m=read();
	for(int i=1;i<=m;i++)
	{
		int x=read(),y=read();
		nx[x]|=bin[y];
	}
	for(int i=1;i<bin[n+1];i++)ct[i]=ct[i-(i&-i)]+1;
	f[bin[n+1]-1][0]=1;
	for(int j=bin[n+1];j>=1;j--)for(int k=0;k<3;k++)if(f[j][k]&&k!=1)
	{
		ln=0;
		for(int l=1;l<=n;l++)if(j&bin[l])tot[++ln]=l;
		for(int S=j;S;S=(S-1)&j)
		{
			int cnt=1;
			for(int l=1;l<=ln;l++)
			{
				if(!(S&bin[tot[l]]))
				{
					int o=nx[tot[l]]&S;
					if(!o){cnt=0;break;}
					cnt=1LL*cnt*(bin[ct[o]+1]-1)%mod;
				}
				else
				{
					int o=nx[tot[l]]&(j^S);
					cnt=1LL*cnt*bin[ct[o]+1]%mod;
				}
			}
			if(k)ad(f[j^S][k],1LL*f[j][k]*cnt%mod);
			else
			{
				if((S&bin[1])&&(S&bin[2]))ad(f[j^S][1],1LL*f[j][k]*cnt%mod);
				else if((S&bin[1])||(S&bin[2]))ad(f[j^S][2],1LL*f[j][k]*cnt%mod);
				else ad(f[j^S][0],1LL*f[j][k]*cnt%mod);
			}
		}
	}
	int ans=0;ad(ans,f[0][2]%mod);
	pr2(ans);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
//freopen("transmitters.in","r",stdin);
//cout<<fixed<<setprecision(6)<<n<<endl;
// transform(s.begin(), s.end(), s.begin(), ::tolower);
//double PI=3.14159265359,c=0;
#define all(v) v.begin(),v.end()
#define endl '\n'
#define ll long long
//#define f(n) for(int i=;i<n;i++)
double PI = acos(-1);
using namespace std;
void fast()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
ll n,arr[1000][3],vist[111][100005],v=1e5;
ll Knapsack(int i,int r)
{
    if(r==0)
     return 0;
    if(i>=n||r<0)
     return (1e9+2);
    if(vist[i][r]!=-1)
     return vist[i][r];

    
    return vist[i][r]=min(Knapsack(i+1,r),Knapsack(i+1,r-arr[i][1])+arr[i][0]);
}
int main()
{
    fast();
    int w,mx=0;
    cin>>n>>w;
    for(int i=0;i<n;i++)
      cin>>arr[i][0]>>arr[i][1];
     memset(vist, -1, sizeof(vist)); 
  for(int i=0;i<1e5+2;i++)
  {
    if(Knapsack(0,i)<=w)
       mx=max(mx,i);
  }
cout<<mx<<endl;
    return 0;
}

Measured memory_bytes: 87040
import itertools

def main():
    # 8通りの方法を調べて最大値　-,-,- から +,+,+
    N, M = map(int, input().split())

    data = [[] for i in range(8)]
    p = list(itertools.product([-1, 1], repeat=3))

    for i in range(N):
        #print(data)
        x, y, z = map(int, input().split())
        for j in range(8):
            tmp = x * p[j][0] + y * p[j][1] + z * p[j][2]
            data[j].append(tmp)
               
    answer = 0
    for d in data:
        d.sort(reverse=True)
        s = sum(d[:M])
        if abs(s) > answer:
            answer = abs(s)
    print(answer)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
H,W,N=map(int,input().split())
r,c=map(int,input().split())

choku=list(input())
ao=list(input())
choku=choku[::-1]
ao=ao[::-1]

Dwn=1
Up=H
Lef=1
Rgt=W
#print(Dwn,r,Up,Lef,c,Rgt)
def chokudai(c):
    global Dwn
    global Up
    global Lef
    global Rgt
    if choku[c]=="D":
        Dwn+=1
    if choku[c]=='U':
        Up-=1
    if choku[c]=='L':
        Lef+=1
    if choku[c]=='R':
        Rgt-=1
    if Dwn>Up or Lef>Rgt:
        print("NO")
        exit()
#chokudai(0)

def kensho(k):
    global Dwn
    global Up
    global Lef
    global Rgt
    if ao[k]=="U":
        Dwn=max(1,Dwn-1)
    if ao[k]=="D":
        Up=min(H,Up+1)
    if ao[k]=="R":
        Lef=max(1,Lef-1)
    if ao[k]=="L":
        Rgt=min(W,Rgt+1)
#print(Dwn,r,Up,Lef,c,Rgt)
for i in range(N):
    kensho(i)
    #print(Dwn,r,Up,Lef,c,Rgt)
    chokudai(i)
    #print(Dwn,r,Up,Lef,c,Rgt)

if Dwn<=H-r+1 and H-r+1<=Up and Lef<=c and c<=Rgt:
    print("YES")
else:
    print("NO")
    #print(Dwn,r,Up,Lef,c,Rgt)
    

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

int main(){
  ll n,m;
  cin>>n>>m;
  if(n!=1 && m!=1){
    cout<<(n-2)*(m-2)<<endl;
  }
  else if(n==1 && m==1){
    cout<<1<<endl;
  }
  else{
    cout<<n*m-2<<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    
    if (((x+r)<=W) && ((x-r)>=0) && ((y+r)<=H) && ((y-r)>=0)) {
        printf("Yes\n");
    } else printf("No\n");
    
    return 0;
}


Measured memory_bytes: 2108
n,m = map(int, input().split())
stu,check = [],[]
for i in range(n):
    stu.append(list(map(int, input().split())))
for i in range(m):
    check.append(list(map(int, input().split())))
for i in range(n):
    dist = float("inf")
    ind = 0
    for j in range(m):
        x = abs(stu[i][0]-check[j][0])+ abs(stu[i][1]-check[j][1])
        if x < dist:
            ind = j
            dist = x
    print(ind+1)

Measured memory_bytes: 3064
#include <cstdio>

int main()
{
    int m, f, r;
    int scores[50];
    char grade[5] = {'A', 'B', 'C', 'D', 'F'};
    while (1)
    {
        scanf("%d %d %d", &m, &f, &r);
        if (m == -1 && f == -1 && r == -1)
        {
            break;
        }
        else if (f == -1 || m == -1)
        {
            printf("%c\n", grade[4]);
        }
        else if ((f + m) >= 80)
        {
            printf("%c\n", grade[0]);
        }
        else if (65 <= (f + m) && (f + m) < 80)
        {
            printf("%c\n", grade[1]);
        }
        else if (50 <= (f + m) && (f + m) < 65)
        {
            printf("%c\n", grade[2]);
        }
        else if (30 <= (f + m) && (f + m) < 50)
        {
            if (r >= 50)
            {
                printf("%c\n", grade[2]);
            }
            else if (-1 <= r && r < 50)
            {
                printf("%c\n", grade[3]);
            }
        }
        else if ((f + m) < 30)
        {
            printf("%c\n", grade[4]);
        }
    }
}


Measured memory_bytes: 2716
def main():
    N = int(input())

    dp = [1] * (N+1)
    for i in range(2, N+1):
        for j in range(i, N+1, i):
            dp[j] = dp[j] + 1
    ans = 0
    for i in range(1, N+1):
        ans = ans + dp[i] * i
    print(ans)

main()


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

int main() {
  int N, M;
  cin >> N >> M;
  
  map<int, priority_queue<int>> jobs;
  
  for(int i = 0; i < N; i++){
    int a, b;
    cin >> a >> b;
    jobs[a].push(b);
  }
  
  int64_t gurantee = 0;
  auto j = jobs.begin(), je = jobs.end();
  priority_queue<pair<int,int>> works;
  for(int i = 1; i <= M; i++){
    for(; j != je && j->first <= i; j++){ 
      works.push({ j->second.top(), j->first });
      j->second.pop();
    }
    
    if(!works.empty()){
      auto p = works.top();
      works.pop();
      gurantee += p.first;
      if(!jobs[p.second].empty()){
        works.push({ jobs[p.second].top(), p.second });
        jobs[p.second].pop();
      }
    }
  }
  
  cout << gurantee << endl;
}

Measured memory_bytes: 10880
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

int n;
pair < int , int > d[N];

bool cmp(pair < int , int > a , pair < int , int > b){
    if(a.second < b.second)
        return 1;
    if(a.second == b.second)
        return a.first < b.first;
    return 0;
}

int main(){
    scanf("%d" , &n);
    for(int i = 1; i <= n; i++){
        int a , b;
        scanf("%d%d" , &a , &b);
        d[i] = {a , b};
    }
    sort(d + 1 , d + n + 1 , cmp);
    /*for(int i = 1; i <= n; i++){
        cout << d[i].first << " " << d[i].second << endl;
    }*/
    long long a = 0;
    for(int i = 1; i <= n; i++){
        if(a + d[i].first <= d[i].second){
            a += d[i].first;
        } else {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>

using namespace std;

int n,d;
string strs[1000];
int dp[20][20];

const int INF=1000000000;

int dfs(int a,int b,string &str1,string &str2){
    if(a==0&&b==2&&str2=="hayashi"&&str1=="yoshoi"){
       // cout<<endl;
    }
    if(a==-1&&b==-1)
        return 0;
    if(a==-1)
        return b+1;
    if(b==-1)
        return a+1;
    if(dp[a][b]!=-1){
        return dp[a][b];
    }
    int res=INF;
    // match
    if(str1[a]==str2[b])
        res=min(res,dfs(a-1,b-1,str1,str2));
    // delete
    res=min(res,dfs(a,b-1,str1,str2)+1);
    res=min(res,dfs(a-1,b,str1,str2)+1);
    // replace
    res=min(res,dfs(a-1,b-1,str1,str2)+1);
    // swap
    if(a-1>=0&&str1[a-1]==str2[b]){
        // ¶ðüêÖ¦½ ÆAÌ¶ðÁ·ê
        res=min(res,dfs(a-2,b-1,str1,str2)+2);
        if(b-2>=0&&str1[a]==str2[b-2])
            res=min(res,dfs(a-2,b-3,str1,str2)+2);
        // Ì¶àêv
        if(b-1>=0&&str1[a]==str2[b-1])
            res=min(res,dfs(a-2,b-2,str1,str2)+1);
        // ³çÉêv
        if(a-2>=0&&b-2>=0&&str1[a-2]==str2[b-1]&&str1[a]==str2[b-2])
            res=min(res,dfs(a-3,b-3,str1,str2)+2);
        if(a-2>=0&&b-2>=0&&str1[a-2]==str2[b-2]&&str1[a]==str2[b-1])
            res=min(res,dfs(a-3,b-3,str1,str2)+1);
    }
    // swap2
    if(b-1>=0&&str2[b-1]==str1[a]){
        // ¶ðüêÖ¦½ ÆAÌ¶ðÁ·ê
        res=min(res,dfs(a-1,b-2,str1,str2)+2);
        if(a-2>=0&&str2[b]==str1[a-2])
            res=min(res,dfs(a-3,b-2,str1,str2)+2);
        // Ì¶àêv
        if(a-1>=0&&str2[b]==str1[a-1])
            res=min(res,dfs(a-2,b-2,str1,str2)+1);
        // ³çÉêv
        if(a-2>=0&&b-2>=0&&str2[b-2]==str1[a-1]&&str2[b]==str1[a-2])
            res=min(res,dfs(a-3,b-3,str1,str2)+2);
        if(a-2>=0&&b-2>=0&&str2[b-2]==str1[a-2]&&str2[b]==str1[a-1])
            res=min(res,dfs(a-3,b-3,str1,str2)+1);
    }
    return dp[a][b]=res;
}

bool check(string &str1,string &str2){

    memset(dp,-1,sizeof(dp));
    if(str1=="abcdef"&&str2=="abdxcef"){
      //  cout<<endl;
    }
    int res=dfs(str1.size()-1,str2.size()-1,str1,str2);
    return res<=d;
}

int main(){
    while(cin>>n>>d&&!(n==0&&d==0)){
        vector<pair<string,string> > vpss;
        for(int i = 0; i < n; i++)
            cin>>strs[i];
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                if(check(strs[i],strs[j])){
                    if(strs[i]<strs[j])
                        vpss.push_back(make_pair(strs[i],strs[j]));
                    else
                        vpss.push_back(make_pair(strs[j],strs[i]));
                }
            }
        }
        sort(vpss.begin(),vpss.end());
        for(int i = 0; i < vpss.size(); i++)
            cout<<vpss[i].first<<","<<vpss[i].second<<endl;
        cout<<vpss.size()<<endl;
    }
    return 0;
}

Measured memory_bytes: 960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (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; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int a, b, c; cin >> a >> b >> c;
    cout << a * b / 2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#define all(c) (c).begin(),(c).end()

using namespace std;

int main(void){

  int n;
  cin >> n;
  vector<int>v(n);
  while(n--)cin >> v[n];
  sort(all(v));
  for(int i=0;i<v.size();i++)
    cout << v[i] << (i<v.size()-1?" ":"\n"); 

  return 0;
}

Measured memory_bytes: 8984
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e - a <= k)
    {
        cout << "Yay!";
    }
    else
    {
        cout << ":(";
    }
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())


def factorization(n):
    arr = dict()
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt

    if temp != 1:
        arr[temp] = 1

    if not arr and n != 1:
        arr[n] = 1

    return arr


def make_divisors(n):
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            yield i
            if i != n // i:
                yield n // i


ans = len(tuple(make_divisors(N - 1))) - 1

it = make_divisors(N)
next(it)

for k in it:
    tmp = N
    while not tmp % k:
        tmp //= k
    if tmp % k == 1:
        ans += 1
print(ans)


Measured memory_bytes: 3064
s = input()
num = len(s)
ans = 0
pos = 0
 
while True:
  c = s[pos]
  count = 0
  for i in range(num - pos):
    if s[pos + i] == c:
      count += 1
    else:
      ans += (count//3)*2  
      if i < num:
        if count % 3 == 1:
          ans += 1
        elif count % 3 == 2:
          ans += 2
          pos += 1
          pos += count
          count = 0
          
      break
  pos += count
  
  if pos >= num:
    ans += (count // 3) * 2 
    if count % 3 != 0:
      ans += 1
 
    break
 
 
print(ans)


Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int maxn = 100000 + 5;
const int maxm = 105;
const int mod = 1e9 + 7;
const ll inf = 1e15 + 7;
int n, x[maxn];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
    cin >> n;
    ++n;
    for(int i = 0; i < n; ++i) cin >> x[i];
    sort(x, x + n);
    int ans = x[1]-x[0];
    for(int i = 2; i < n; ++i) {
        ans = gcd(ans, x[i]-x[i-1]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
from collections import defaultdict


class UF:
    def __init__(self, _n):
        assert _n >= 0
        self._count = _n
        self._parent = list(range(_n))
        self._rank = [1] * _n

    def find(self, p):
        assert p >= 0 & p < len(self._parent)
        while p != self._parent[p]:
            self._parent[p] = self._parent[self._parent[p]]    # path compression by halving
            p = self._parent[p]
        return p

    def count(self):
        return self._count

    def connected(self, p, q):
        return self.find(p) == self.find(q)

    def union(self, p, q):
        root_p = self.find(p)
        root_q = self.find(q)
        if root_p == root_q:
            return
        
        if self._rank[root_p] < self._rank[root_q]:
            self._parent[root_p] = root_q
        elif self._rank[root_p] > self._rank[root_q]:
            self._parent[root_q] = root_p
        else:
            self._parent[root_q] = root_p
            self._rank[root_p] += 1
        self._count -= 1


n, k, l = map(int, input().split())
uf_road, uf_rail = UF(n), UF(n)

for _ in range(k):
    p, q = map(int, input().split())
    uf_road.union(p-1, q-1)

for _ in range(l):
    p, q = map(int, input().split())
    uf_rail.union(p-1, q-1)

d = defaultdict(int)
for i in range(n):
    d[uf_road.find(i), uf_rail.find(i)] += 1
#print(d)
#print(' '.join(str(d[(uf_road.find(i), uf_rail.find(i))]) for i in range(n)))
print(*(d[uf_road.find(i), uf_rail.find(i)] for i in range(n)))

Measured memory_bytes: 56128
#解答より
N=int(input())

def dfs(s):
  if int(s)>N:
    return 0
  if all (s.count(c)>0 for c in "753"):
    ret=1
  else:
    ret=0
    
  for c in "753":
    ret=ret+dfs(s+c)
  
  return ret

print (dfs("0"))

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

void fnInput(int& rnAchieve, vector<int>& rvnPrice, vector<vector<int>>& rvvnSkill)
{
  int nPriceSiz, nSkillSiz;
  cin >> nPriceSiz >> nSkillSiz >> rnAchieve;
  rvnPrice.resize(nPriceSiz);
  rvvnSkill.resize(nPriceSiz, vector<int>(nSkillSiz));

  for (int i = 0; i < rvvnSkill.size(); i++)
  {
    cin >> rvnPrice[i];

    for (int j = 0; j < rvvnSkill[i].size(); j++)
      cin >> rvvnSkill[i][j];
  }
}

int fnMinPriceSkillup(int nAchieve, const vector<int> cnrvnPrice, 
                      const vector<vector<int>>& cnrvvnSkill)
{
  int nMinPrice = INT_MAX;

  for (int nCtl = 0; nCtl < (1 << cnrvnPrice.size()); nCtl++)
  {
    int nPrice = 0;
    vector<int> vnSumSkill(cnrvvnSkill[0].size());

    for (int ny = 0; ny < cnrvnPrice.size(); ny++)
      if (nCtl & (1 << ny))
      {
        for (int nx = 0; nx < cnrvvnSkill[ny].size(); nx++)
          vnSumSkill[nx] += cnrvvnSkill[ny][nx];

        nPrice += cnrvnPrice[ny];
      }

    bool bRslt = true;

    for (int nSumSkill : vnSumSkill)
      if (nSumSkill < nAchieve)
      {
        bRslt = false;
        break;
      }

    if (bRslt)
      nMinPrice = min(nMinPrice, nPrice);
  }
  if (nMinPrice == INT_MAX)
    return -1;
  else
    return nMinPrice;
}
  
int main()
{
  int nAchieve;
  vector<int> vnPrice;
  vector<vector<int>> vvnSkill;

  fnInput(nAchieve, vnPrice, vvnSkill);
  cout << fnMinPriceSkillup(nAchieve, vnPrice, vvnSkill) << endl;

  return 0;
}

Measured memory_bytes: 3624
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

        for (int i = 0; i < m; i++) {
            int t1 = in.nextInt() - 1;
            int t2 = in.nextInt() - 1;
            a[t1][t2] = 1;
            a[t2][t1] = 1;
        }
        List<Integer> order = new ArrayList<>();
        order.add(0);
        List<Integer> remain = new ArrayList<>();
        for (int i = 1; i < n; i++) {
            remain.add(i);
        }
        System.out.println(f(order, remain, a));
    }

    static int f(List<Integer> order, List<Integer> remain, int edges[][]) {
        if (remain.size() == 0) {
            int cur = order.get(0);
            int next;
            for (int p = 1; p < order.size(); p++) {
                next = order.get(p);
                if (edges[cur][next] == 1 || edges[next][cur] == 1) {
                    cur = next; 
                } else {
                    return 0;
                }
            }
            return 1;
        }

        int total = 0;
        for (int p = 0; p < remain.size(); p++) {
            order.add(remain.get(p));
            remain.remove(p);
            total += f(order, remain, edges);
            remain.add(p, order.get(order.size() - 1));
            order.remove(order.size() - 1);
        }
        return total;
    }
}

Measured memory_bytes: 22740
A, B = map(int, input().split())
print(100, 100)
ans = [["."]*50 + ["#"]*50 for i in range(100)]


for a in range(A - 1):
    ans[2*(a // 25)][99 - 2*(a % 25)] = "."
for b in range(B - 1):
    ans[2*(b // 25)][2*(b % 25)] = "#"
for l in ans:
    print("".join(l))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int x, y, a, b, c, u = 0, v = 0, w = 0;
    ll p[100005] = {}, q[100005] = {}, r[100005] = {}, z = 0;
    vector<pair<ll, int>> d;
    cin >> x >> y >> a >> b >> c;
    for (int i = 0; i < a; i++) cin >> p[i], d.push_back({p[i], 1});
    for (int i = 0; i < b; i++) cin >> q[i], d.push_back({q[i], 2});
    for (int i = 0; i < c; i++) cin >> r[i], d.push_back({r[i], 3});
    sort(d.begin(), d.end()); reverse(d.begin(), d.end());
    for (auto i : d) {
        if (i.second == 1) {
            if (u < x) u++, z += i.first;
        } else if (i.second == 2) {
            if (v < y) v++, z += i.first;
        } else {
            w++, z += i.first;
        }
        if (u + v + w == x + y) break;
    }
    cout << z;
}


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

using namespace std;

using ll = long long;

int n;
vector<ll> h, arr, dp, segt;

void update(int idx, ll x){
    idx += (n + 1);
    segt[idx] = x;
    for(; idx > 1; idx /= 2){
        segt[idx/2] = max(segt[idx], segt[idx ^ 1]);
    }
}

ll query(int l, int r){
    ll res = -1;
    l += (n + 1), r += (n + 1);
    for(; l < r; l /= 2, r /= 2){
        if(l & 1) res = max(res, segt[l++]);
        if(r & 1) res = max(res, segt[--r]);
    }
    return res;
}

int main(){
    cin>>n;
    h.resize(n); arr.resize(n); dp.resize(n+1); segt.resize(2 * (n + 1));
    for(int i = 0; i < n; i++) cin>>h[i];
    for(int i = 0; i < n; i++) cin>>arr[i];
    for(int i = 0; i < n; i++){
        // for(int j = 0; j < h[i]; j++){
            ll x = query(0, h[i]) + arr[i];
            update(h[i], x);
            // dp[h[i]] = max(dp[h[i]], dp[j] + arr[i]);
        // }
    }
    ll res = segt[1];
    // for(auto x : dp){
    //     res = max(res, x);
    // }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 8064
#ifdef LOCAL
//#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

int main() {
#ifdef LOCAL
    freopen("in", "r", stdin);
    //    freopen("out", "w", stdout);
#endif
    ios::sync_with_stdio(0), cin.tie(0);
    string s;
    cin >> s;
    int ans = 700;
    for (int i = 0; i < 3; i++)
        ans += s[i] == 'o' ? 100 : 0;
    cout << ans << endl;
    return 0;
}


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

void solve(long long N, long long C, std::vector<long long> x, std::vector<long long> v){
    vector<LL> l2r(2*N, 0);
    vector<LL> r2l(2*N, 0);
    LL accr=0, accl=0;

    for(LL i=0; i<N; i++){
        accr += v[i];
        accl += v[N-i-1];
        r2l[N+i] = max(accr-2*x[i], (i>0 ? r2l[N+i-1] : 0));
        l2r[N+i] = max(accr-x[i], (i>0 ? l2r[N+i-1] : 0));
        l2r[N-i-1] = max(accl-2*(C-x[N-i-1]), (i>0 ? l2r[N-i] : 0));
        r2l[N-i-1] = max(accl-(C-x[N-i-1]), (i>0 ? r2l[N-i] : 0));
    }

    auto ans=max(r2l[0], l2r[2*N-1]);
    for(int i=1; i<=N-1; i++){
        ans = max(ans, r2l[i]+r2l[i+N-1]);
        ans = max(ans, l2r[i]+l2r[i+N-1]);
    }
    cout << ans << endl;

}

int main(){
    long long N;
    scanf("%lld",&N);
    long long C;
    scanf("%lld",&C);
    std::vector<long long> x(N);
    std::vector<long long> v(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&v[i]);
    }
    solve(N, C, std::move(x), std::move(v));
    return 0;
}


Measured memory_bytes: 4992
h,w=map(int,input().split())
n=10
d=[]
for i in range(n):
    d.append(list(map(int,input().split())))
a=[]
for i in range(h):
    a.append(list(map(int,input().split())))

def wf(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
    return d


d=wf(d)
cnt=0
for i in range(h):
    for j in range(w):
        if a[i][j]==-1:continue
        cnt+=d[a[i][j]][1]
print(cnt)


Measured memory_bytes: 40284
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	double a[n],sum = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		sum += a[i];
	}
	sum = sum / n;
	int va = 100000000;
	int ans;
	int rem = sum;
	for(int j = -1; j < 2; j++){
		sum = rem + j;
		ans = 0;
		for(int i = 0; i < n; i++)
			ans += pow(a[i] - sum, 2);
		va = min(va , ans);
	}
	cout << va << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;
 
public class Main {
    static final int INF = 1000000000;         
    static int cmps = 0;
     
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] s = new int[n];
        for (int i = 0; i < n; ++i) s[i] = input.nextInt();
        mergeSort(s, 0, n);
        System.out.print(s[0]);
        for (int i = 1; i < n; ++i) System.out.print(" " + s[i]);
        System.out.println("");
        System.out.println(cmps);
    }              
     
    static void mergeSort(int[] A, int left, int right) {
        if (left + 1 < right) {
            int mid = (left + right) / 2;
            mergeSort(A, left, mid);
            mergeSort(A, mid, right);
            merge(A, left, mid, right);
        }
    }
     
    static void merge(int[] A, int left, int mid, int right) {
        int n1 = mid - left;
        int n2 = right - mid;
        int[] L = new int[n1 + 1];
        int[] R = new int[n2 + 1];
        for (int i = 0; i < n1; ++i) L[i] = A[left + i];
        for (int i = 0; i < n2; ++i) R[i] = A[mid + i];
        L[n1] = R[n2] = INF;
        int i, k;
        i = k = 0;
        for (int t = left; t < right; ++t) {
            if (L[i] < R[k]) {
                A[t] = L[i++];
                ++cmps;
            } else {
                A[t] = R[k++];
                ++cmps;
            }
        }
    }
}

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

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

  if(a=='1'){a='9';}
  else{a='1';}
  if(b=='1'){b='9';}
  else{b='1';}
  if(c=='1'){c='9';}
  else{c='1';}
  
  cout << a << b << c << endl;


}


Measured memory_bytes: 256