akhauriyash/Code-Regression huggingface dataset:
import math
import itertools

n, m, q = map(int, input().split(" "))
aL = []
_max = 0

for i in range(q):
    aL.append(list(map(int, input().split(" "))))

zLi = itertools.combinations_with_replacement(list(range(m + 1)), n)
for t in zLi:
    if t[0] == 0:
        continue
    _sum = 0
    for a in aL:
        if t[a[1] - 1] - t[a[0] - 1] == a[2]:
            _sum += a[3]
    _max = max(_max, _sum)

print(_max)

Measured memory_bytes: 67792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ALDS1_7_D
{
    class Program
    {
        static int pos;
        static int[] pre, ino;
        static List<int> post = new List<int>();

        static void rec(int l, int r)
        {
            if (l >= r) return;
            int root = pre[pos++];
            int m = ino.TakeWhile(s => s != root).Count();
            rec(l, m);
            rec(m + 1, r);
            post.Add(root);
        }
        static void Main(string[] args)
        {
            int n = scan[0];
            pre = scan;
            ino = scan;

            rec(0, n);

            var sb = new StringBuilder();
            foreach (var item in post)
            {
                sb.Append(item + " ");
            }
            var ans = sb.ToString().Trim();
            Console.WriteLine(ans);
        }

        static int[] scan
        {
            get { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
        }
    }
}

Measured memory_bytes: 9668
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long k = sc.nextLong();
    long x = Math.max(0,a-k);
    long y = 0;
    if(x!=0)y=b;
    else y=Math.max(0,b-(k-a));
    System.out.println(x+" "+y);
  }
}


Measured memory_bytes: 22740
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

int N;
int A[100000+2];

int iabs(int n){
    return (0<n) ? n : -n;
}

int main(void){
    GI(N);
    A[0]=0;
    REP(i,N)
        GI(A[i+1]);
    int sum = 0;
    REP(i,N+1){
        int a = A[i+1] - A[i];
        sum += iabs(a);
    }
    REP(i,N){
        if((A[i] <= A[i+1] && A[i+1] <= A[i+2]) || (A[i] >= A[i+1] && A[i+1] >= A[i+2]))
            printf("%d\n",sum);
        else{
            int a = iabs(A[i] - A[i+1]) + iabs(A[i+1] - A[i+2]);
            int b = iabs(A[i] - A[i+2]);
            printf("%d\n",sum - a + b);
        }
    }
    return 0;
}

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

using namespace std;

const int N=2e3+4, INF=1e9;
int pos[2][N], dp[N][N], cb[N][N], cw[N][N], n;
int main()
{
	cin >> n;
	for(int i = 1; i <= 2*n; i++)
	{
		char c; int x;
		cin >> c >> x;
		pos[(c=='W')][x]=i;
	}
	for(int i = 1; i <= n; i++)
	{
		int bb=0;
		for(int j = 1; j < i; j++)
		{
			if(pos[0][j]>pos[0][i]) bb++;
		}
		cb[i][0]=bb;
		for(int j = 1; j <= n; j++)
		{
			cb[i][j]=cb[i][j-1]  + (pos[1][j]>pos[0][i]);
		}
	}
	for(int i = 1; i <= n; i++)
	{
		int ww=0;
		for(int j = 1; j < i; j++)
		{
			if(pos[1][j]>pos[1][i]) ww++;
		}
		cw[i][0]=ww;
		for(int j = 1; j <= n; j++)
		{
			cw[i][j]=cw[i][j-1] + (pos[0][j]>pos[1][i]);
		}
	}
	for(int i = 0; i <= n; i++)
	{
		for(int j = 0; j <= n; j++)
		{
			dp[i][j]=INF;
		}
	}
	dp[0][0]=0;
	for(int i = 0; i <= n; i++)
	{
		for(int j = 0; j <= n; j++)
		{
			if(i!=0) dp[i][j]=min(dp[i][j], dp[i-1][j] + cb[i][j]);
			if(j!=0) dp[i][j]=min(dp[i][j], dp[i][j-1] + cw[j][i]);
		}
	}
	cout << dp[n][n];
}

Measured memory_bytes: 47360
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

constexpr lli inf = 10000 * 10000;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	lli x, y, z;
	cin >> x >> y >> z;

	cout << z << " " << x << " " << y << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <cmath>
#include <bitset>
#include <queue>
#include <set>
#include <numeric>
#include <unordered_set>
#include <iomanip>
#include <string>
#include <stack>
#include <cstring>
#include <sstream>

using namespace std;


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

    int x, y;
    cin >> x >> y;
    for (int i = 0; i <= x; ++i) {
      if (i * 2 + (x - i) * 4 == y) {
        cout << "Yes";
        return 0;
      }
    }
    cout << "No";
}


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

using namespace std;
typedef long long ll;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	int n; cin >> n; n %= 10;
  	cout << (n == 3 ? "bon" : (n == 0 || n == 1 || n == 6 || n == 8) ? "pon" : "hon") << endl;
  	return 0;
}


Measured memory_bytes: 3644
#include<stdio.h>
int main()
{
	int h, w;
	int i, j;
	while (1)
	{
		scanf("%d%d", &h, &w);
		if (h == 0 && w == 0) 
		{
			break;
		}

		for (i = 0;i < h;i++)
		{
			for (j = 0;j < w;j++)
			{
				if (j % 2 == 1)
				{
					if (i % 2 == 1)
					{
						printf("#");
					}

					else
					{
						printf(".");

					}
				}

				else
				{
					if (i % 2 == 1)
					{
						printf(".");
					}

					else 
					{
						printf("#");
					}
				}
			}

			printf("\n");
		}

		printf("\n");

	}
	return 0;
}


Measured memory_bytes: 2056
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 998244353
#define N 405
ll ara[N],dp[N][N];
ll add[N][N];
ll solve(int l,int r)
{
    if(l==r) return 0;
    if(dp[l][r]!=-1) return dp[l][r];
    dp[l][r]=LLONG_MAX;
    for(int i=l;i<r;i++)
    {
        dp[l][r]=min(dp[l][r],solve(l,i)+solve(i+1,r)+add[l][r]);

    }
    return  dp[l][r];
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++) cin>>ara[i];
    for(int i=0;i<n;i++)
    {
        ll temp=0;
        for(int j=i;j<n;j++)
        {
            temp+=ara[j];
            add[i][j]=temp;
        }
    }
    memset(dp,-1,sizeof dp);
    cout<<solve(0,n-1)<<endl;
}


Measured memory_bytes: 6176
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  n,m = readInts()
  A = set()
  B = set()
  for i in range(m):
    a,b = input().split()
    if a == '1':
      A.add(b)
    if b == str(n):
      B.add(a)
  print('POSSIBLE' if A & B else 'IMPOSSIBLE')
  # A & B 共通のものがあればよい
  # A = [3] B = [3]とかなら 1 - 3 , 3 - 6への経路がある！！
if __name__ == '__main__':
  main()

Measured memory_bytes: 23116
<?php

class IO {

	//input
	private $buf = [];
	private $count = 0;
	private $pointer = 0;

	public function nextLine() {
		$ret = '';
		if($this->hasNext()){
			while($this->hasNext()){
				$ret .= $this->next();
			}
		}else{
			$ret = trim(fgets(STDIN));
		}

		return $ret;
	}

	public function next() {
		if(!$this->hasNext()) {
			$str = trim(fgets(STDIN));
			$this->buf = explode(' ',$str);
			$this->count = count($this->buf);
			$this->pointer = 0;
		}

		return $this->buf[$this->pointer++];
	}

	public function hasNext() {
		return $this->pointer < $this->count;
	}

	public function nextInt() {
		return (int)$this->next();
	}

	public function nextDouble() {
		return (double)$this->next();
	}

	//output
	public function println($str = '') {
		echo $str . PHP_EOL;
	}
}

class Math {
	public static function gcd($x,$y) {
		if ($y === 0)return $x;
		else return Math::gcd($y,$x % $y);
	}

	public static function lcm($x,$y) {
		return $x / Math::gcd($x,$y) * $y;
	}
}

$io = new IO();


$N = $io->nextInt();

$A = array();
for($i = 0;$i < $N;$i++) {
	$A[] = $io->nextInt();
}

$T = array_count_values($A);
$ans = 0;
foreach($T as $key => $value) {
	$ans += $value % 2;
}

$io->println($ans);

?>


Measured memory_bytes: 17140
N,K = map(int,input().split())
A = list(map(int,input().split()))

B = A.copy()
def update(A):
    res = [0]*N
    for i in range(N):
        if A[i]+i+1<N:
            res[A[i]+i+1] -= 1
        res[max(0,i-A[i])] += 1
    for i in range(N-1):
        res[i+1] += res[i]
    return res

while K:
    B = update(B)
    K -= 1
    if sum(B)==N**2:
        break

print(*B)

Measured memory_bytes: 151756
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  if(N % 1000 != 0)
    cout << 1000 - N % 1000 << "\n";
  else
    cout << 0 << "\n";
  
  return 0;
}


Measured memory_bytes: 3640
import math
n = int(input())
x_list = list(map(int,input().split()))
y_list = list(map(int,input().split()))
def distance(X,Y,N):
    t= 0
    for i  in range(len(X)):
        z = (abs(X[i] - Y[i]))**N
        t += z
    return math.pow(t,1/N)    
def chebi(X,Y):
    abs_list= []
    for i in range(len(X)):
        abs_list.append(abs(X[i]-Y[i]))
    return max(abs_list)
print(distance(x_list,y_list,1))
print(distance(x_list,y_list,2))
print(distance(x_list,y_list,3))
print(chebi(x_list,y_list))


Measured memory_bytes: 5704
#include <stdio.h>

int main (void)
{
    int R;
    scanf("%d",&R);
    if(R<1200)
    {
        puts("ABC");
    }else{
        if(R<2800)
        {
            puts("ARC");
        }else{
            puts("AGC");
        }
    }
    return 0;
}

Measured memory_bytes: 128
import java.lang.String.format

fun main(args: Array<String>) {
    val line = readLine()!!.split(' ').map { it.toInt() }
    val rank = IntArray(line[0] + 1) { 1 }
    val cities = (1..line[1]).map {
        val l = readLine()!!.split(' ').map { it.toInt() }
        Triple(it, l[0], l[1])
    }.sortedBy { it.third }
    val sb = StringBuilder()
    cities.map { Pair(it, rank[it.second]++) }
            .sortedBy { it.first.first }
            .forEach {
                sb.append(format("%06d%06d\n", it.first.second, it.second))
            }
    println(sb)
}


Measured memory_bytes: 141464
#include <iostream>
using namespace std;
int main()
{
  string s; cin >> s;
  for (int i = 1; i < s.size(); i++)
  {
    if (s[i] == s[i - 1])
    {
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    int cnt = 0;
    for (int i=1; i<=n; i++){
        int note = to_string(i).length();
        if ( note%2!=0 ){
            cnt++; 
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3756
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
BC=[list(map(int,input().split())) for i in range(Q)]
goukeiti=sum(A)
atai=[0]*(10**5+1)
for i in A:
    atai[i-1]+=1
for i in BC:
    if atai[i[0]-1]!=0:
        kotae=atai[i[0]-1]*i[1]-atai[i[0]-1]*(i[0])
        atai[i[1]-1]+=atai[i[0]-1]
        atai[i[0]-1]=0
        goukeiti+=kotae
        print(goukeiti)
    else:
        print(goukeiti)

Measured memory_bytes: 32284
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
using namespace std;


int main(){
  int a,b,x;
  std::cin >> a>>b>>x;
if((x<a)||((a+b)<x)){
  std::cout << "NO" << '\n';
}else{
  std::cout << "YES" << '\n';
}
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int jrk, wkt, kec;
	cin >> jrk;
	cin >> wkt;
	cin >> kec;
		
	if(kec* wkt >= jrk){
		cout << "Yes"<<endl;
	}
	else{
		cout << "No" << endl;
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  int Max = *max_element(p.begin(), p.end());
  int sum = accumulate(p.begin(), p.end(), 0);
  int ans = (sum - Max) + (Max / 2);
  cout << ans << endl;
}

Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    V vec(n);
    rep(i,n)cin>>vec[i];
    ll sum=0;
    rep(i,n)sum+=abs(vec[i]);
    ll negative=0;
    bool f=false;
    rep(i,n){
        if(vec[i]<0){
            negative++;
        }
        if(vec[i]==0){
            f=true;
        }
    }
    rep(i,n)vec[i]=abs(vec[i]);
 //   cout<<negative<<endl;
    if(f||negative%2==0){
        //cout<<"hjh"<<endl;
        cout<<sum<<endl;
    }else{
        sort(all(vec));
        cout<<sum-abs(vec[0])*2<<endl;
    }
}


Measured memory_bytes: 1024
from sys import stdin, setrecursionlimit


def initialize_cmb(m, mod=10 ** 9 + 7):
    fac = [1]
    finv = [1]
    inv = [0] * (m + 1)
    if m > 1:
        fac.append(1)
        finv.append(1)
        inv[1] = 1
        pre_fac = 1
        pre_finv = 1
        for i in range(2, m + 1):
            pre_fac = pre_fac * i % mod
            fac.append(pre_fac)
            inv[i] = mod - inv[mod % i] * (mod // i) % mod
            pre_finv = pre_finv * inv[i] % mod
            finv.append(pre_finv)
    return fac, finv


def cmb(n, k, fac, finv, mod=10 ** 9 + 7):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    input = stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = map(int, input().split())

    fac, finv = initialize_cmb(n, mod)

    c_n = []
    for i in range(n + 1):
        c_n.append(cmb(n, i, fac, finv))
    c_n_1 = []
    for i in range(n):
        c_n_1.append(cmb(n - 1, i, fac, finv))

    ans = 0
    for i in range(min(k + 1, n)):
        ans += c_n[i] * c_n_1[n - i - 1]
        ans %= mod
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion

#define int long long


signed main()
{
    int n, p;
    while(cin>>n>>p, n) {
        stack<int> w;
        for(int i=0; i<p; ++i) w.push(1);
        int memo[n] = {0};
        int c = 0;
        while(true) {
            if(w.empty()) {
                for(int i=0; i<memo[c]; ++i) w.push(1);
                memo[c] = 0;
                c  = (c+1)%n;
                continue;
            }
            w.pop();
            memo[c]++;
            if(memo[c]==p) {
                cout << c << endl;
                break;
            }
            c  = (c+1)%n;
        }
    }
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> p(n, 0);
    vector<int> q(n, 0);
    vector<int> r(n, 0);
    for (size_t i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    for (size_t i = 0; i < n; i++)
    {
        cin >> q[i];
    }
    int pp = 0;
    int qq = 0;
    for (size_t i = 0; i < n; i++)
    {
        r[i] = i + 1;
    }

    while (p != r)
    {
        next_permutation(r.begin(), r.end());
        pp++;
    }
    for (size_t i = 0; i < n; i++)
    {
        r[i] = i + 1;
    }
    while (q != r)
    {
        next_permutation(r.begin(), r.end());
        qq++;
    }
    cout << abs(pp - qq) << endl;
    return 0;
}

Measured memory_bytes: 256
$N=<>;
@_=(0,(glob<>),0);
$x+=abs($_-$p),$p=$_ for@_;
for(1..$N){
	print$x-(abs($_[$_]-$_[$_-1])+abs($_[$_+1]-$_[$_]))+abs($_[$_+1]-$_[$_-1]),$/
}


Measured memory_bytes: 26496
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include<map>
#include <utility>
#include <math.h>
using namespace std;
int a = 0, b = 0, c = 0, d = 0, e[1050] = {}, f[100010];
double syo = 0, su = 0;
long long mur, kmr, yju, counto = 0,counto1=0;
char mado[105];
string rik;
bool mazi[110], gi[110],zi,manji;
pair<int, int>n[110];
vector<int> aa[50] = {}, bb, cc;
map<int, int>kazu;
int main() 
{
	cin >> a >> b;
	
	for (int i = 0; i < a; i++) {
		cin >> c;
		for (int j = 0; j < c; j++) {
			cin >> d;
			e[d]++;
		}
	}
	for (int i = 0; i < b+1; i++) {
		if (e[i] == a) {
			counto++; 
				//cout << i << endl;
		
		}
	}
	cout << counto << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 
using namespace std;
int main()
{
    int a,b;
    while (~scanf("%d %d", &a,&b)) {
        if (a>=13) printf("%d\n", b);
        else if(a>=6) printf("%d\n", b/2);
        else puts("0");
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int N;
    scanf("%d\n",&N);
	int j = 0;
	int size, number;
	for (int i = 0;i <= N+1;i++)
		if (2 * N == i * (i - 1)) {
			j = 1;
			number = i;
			size = (2 * N) / number;
			break;
		}
	if (j == 0)
		 printf("No\n") ;
	else {
		printf("Yes\n%d\n",number);
		int set[number][size];

		

		int i = 1;
		for (int l = 0;l < number;l++) {
                       int n=0;
			for (int k = 0;k < size;k++) {
				while(n<l) {
					set[l][k++] = set[n++][l - 1];
				}
				set[l][k] = i;
				i++;
			}
			printf("%d ", size);
			for (int m = 0;m < size;m++)
				printf("%d ", set[l][m]);
			printf("\n");
		}
	}
}

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

using namespace std;
int ind[105];
pair<long long,long long > D[105];
int main(){
   // srand(time(0));
    auto start = chrono::system_clock::now();

    int n;cin >> n;
    for(int i=1;i<=n;++i){
        cin >> D[i].first >> D[i].second;
        ind[i]=1;
    }
    long long x,y;x=0;y=0;
    int cnt2=0;
    double ans=0;
    while(1){
        bool flag=0;

        for(int i=1;i<=n;++i){
            long long X=x+D[i].first*ind[i];
            long long Y=y+D[i].second*ind[i];
            if(X*X+Y*Y>x*x+y*y){
                flag=1;
                x=X;y=Y;
                ind[i]*=-1;
                
            }
        }
        if(!flag){
            ans=max(ans,sqrt(x*x+y*y));
            x=0;y=0;
            auto en = std::chrono::system_clock::now();
            chrono::duration<double> elapsed= en-start;
            if(elapsed.count()>1.95){
                break;
            }
            for(int i=1;i<=n;++i){
                int u=(rand()*rand())%2;
                if(u%2){
                    x+=D[i].first;
                    y+=D[i].second;
                    ind[i]=-1;
                }
                else{
                    ind[i]=1;
                }
            }
        }
    }
    printf("%.16f\n",ans);

    return 0;

}


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

int euc(int x, int y) {
    if (y == 1) {
        return y;
    }

    if (y > x) {
        int tmp = x;
        x = y;
        y = tmp;
    }

    int mod = x % y;
    if (mod == 0) {
        return y;
    }

    return euc(y, mod);
}

int main() {
    int64_t A, B;
    cin >> A >> B;
    int64_t uc = euc(A, B);
    cout << A * B / uc << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// ---------------------------------------------------------------------------



int main(){
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    ll sum_X = 0;
    vector<int> x(N);
    for(int i=0; i<N; i++){
        cin >> x[i];        
    }
    vector<int> y(M);
    for(int i=0; i<M; i++){
        cin >> y[i];
    }
    for(int i=1; i<N; i++){
        ll now = x[i] - x[i-1];
        now *= i;
        now %= mod;
        now *= (N-i);
        now %= mod;
        sum_X += now;
        sum_X %= mod;
    }
    ll sum_Y = 0;
    for(int i=1; i<M; i++){
        ll now = y[i] - y[i-1];
        now *= i;
        now %= mod;
        now *= (M-i);
        now %= mod;
        sum_Y += now;
        sum_Y %= mod;
    }
    ll ans = (sum_X * sum_Y)%mod;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4036
(let* ((h (read))
       (w (read))
       (a (make-array 1 :element-type 'string
                        :initial-element "...................................................."
                        :adjustable t
                        :fill-pointer 1))
       (ans T))
  (loop repeat h do (vector-push-extend (format nil ".~A." (read-line)) a))
  (vector-push-extend "...................................................." a)
  (loop for i from 1 upto h do
        (loop for j from 1 upto w while ans do
              (if (equal (char (aref a i) j) #\#) (if (and (equal (char (aref a (- i 1)) j) #\.) (equal (char (aref a (1+ i)) j) #\.) (equal (char (aref a i) (1+ j)) #\.) (equal (char (aref a i) (- j 1)) #\.)) (setf ans nil)))))
  (format t "~A~%" (if ans "Yes" "No")))



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

int main() {
  double A, B, H, M;
  cin >> A >> B >> H >> M;
  double k1 = 360.0 / 12.0 * H;
  double k2 = 360.0 / 60.0 * M;
  k1 += 30.0 / 60.0 * M;
  double k3 = abs(k1 - k2);
  k3 = min(k3, 360 - k3);
  double rad = k3 * M_PI / 180.0;
  double ans = A * A + B * B - 2.0 * A * B * cos(rad);
  cout << fixed << setprecision(50) << sqrt(ans) << "\n";
}

Measured memory_bytes: 4116
#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, ans = 0;
    cin >> n;
    akari<int> ds(n);
    for (int i = 0; i < n; i++)
    {
        cin >> ds[i];
    }
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
        {
            ans += ds[i] * ds[j];
        }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}


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

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

void solve()
{
	int x,n;cin >> x >> n;
	vector<int> hash(n);
	if(n==0)
	{
		cout << x;
		return;
	}
	for(int &x:hash) cin >> x;
	//sort(hash.begin(),hash.end());
	int diff = INF;
	int ans;
	for(int i = -200;i<=200;++i)
	{
		if(find(hash.begin(),hash.end(),i) == hash.end())
		{
			if(diff > abs(x-i))
			{
				ans = i;
				diff=abs(x-i);
			}
		}
	}
	cout << ans;
}

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

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    double maxv = -1.0;
    int maxw, maxs;
    REP(iA, 31){
        REP(iB, 31){
            int water = 100 * A * iA + 100 * B * iB;
            if(water > F) continue;
            int maxsugar = min(F - water, water / 100 * E);
            int maxiC = maxsugar / C;
            REP(iC, maxiC + 1){
                int maxsugar2 = maxsugar - iC * C;
                int iD = maxsugar2 / D;
                int sugar = iC * C + iD * D;
                double val = (double)(sugar) / (double)(sugar + water);
                if(val > maxv){
                    maxv = val;
                    maxw = water;
                    maxs = sugar;
                }
            }
        }
    }

    cout << maxw + maxs << " " << maxs;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
    public static final BigInteger MAX_VALUE = new BigInteger("1000000000000000000") ;

    public static BigInteger solve(BigInteger [] arr) {
        BigInteger result = BigInteger.ONE;
        for (BigInteger value : arr) {

            result = value.multiply(result);
            if (result.compareTo(MAX_VALUE) > 0) return new BigInteger("-1");
        }
        return result;
    }
    public static void main(String[] args) {
        Scanner sn = new Scanner(System.in);

        int n = sn.nextInt();
        BigInteger [] arr = new BigInteger[n];
        for(int i = 0; i<n ; i++) {
            arr[i] = new BigInteger(sn.next());
            if(arr[i].compareTo(BigInteger.ZERO) == 0) {
                System.out.println(0);
                return;
            }
        }
        System.out.println(solve(arr).toString());
    }
}

Measured memory_bytes: 65656
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int H = sc.nextInt();
		int W = sc.nextInt();
		
		int count = 0;
        for (int i = 0; i < N; i++) {
            int currnetH = sc.nextInt();
		    int currentW = sc.nextInt();
		    if (H <= currnetH && W <= currentW) {
		        count++;
		    }
        }
        
        System.out.println(count);
	}
}

Measured memory_bytes: 25060
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<functional>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define INF 1000000000

struct St {
	int node;
	int money;
	int attack;
	St(int _node, int _money, int _attack) {
		node = _node;
		money = _money;
		attack = _attack;
	}

	bool operator >(const St &e) const {
		return attack > e.attack;
	}
};


int dp[101][101]; // i?????????????±???§??????????????????j????????????????\???????????????°???????°????
int main()
{
	int N, M, L;
	while (cin >> N >> M >> L, N || M || L) {
		pair<int, int> p[101][101];
		REP(i, 0, N) {
			REP(j, 0, N) {
				p[i][j].first = p[i][j].second = INF;
			}
		}
		REP(i, 0, M) {
			int A, B, D, E;
			cin >> A >> B >> D >> E;
			p[A - 1][B - 1].first = p[B - 1][A - 1].first = D;
			p[A - 1][B - 1].second = p[B - 1][A - 1].second = E;
		}

		REP(i, 0, N) {
			REP(j, 0, L + 1) {
				dp[i][j] = INF;
			}
		}
		dp[0][L] = 0;

		priority_queue<St, vector<St>, greater<St>> pq;
		St st(0, L, 0);
		pq.push(st);
		while (!pq.empty()) {
			St now = pq.top();
			pq.pop();

			int nowN = now.node;
			int nowM = now.money;
			int nowA = now.attack;

			if (dp[nowN][nowM] < nowA) continue;
			REP(i, 0, N) {
				if (p[nowN][i].first == INF) continue;

				/* ??????????????? */
				if (p[nowN][i].first <= nowM) {
					int nextM = nowM - p[nowN][i].first;
					int nextA = nowA;

					if (nextA < dp[i][nextM]) {
						dp[i][nextM] = nextA;
						St nextS(i, nextM, nextA);
						pq.push(nextS);
					}
				}


				/* ????????????????????? */
				int nextM = nowM;
				int nextA = nowA + p[nowN][i].second;

				if (nextA < dp[i][nextM]) {
					dp[i][nextM] = nextA;
					St nextS(i, nextM, nextA);
					pq.push(nextS);
				}
			}
		}

		int ans = INF;
		REP(i, 0, L + 1) {
			ans = min(ans, dp[N - 1][i]);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3372
r, b, g, n=map(int, input().split())
rm=n//r
bm=n//b
ans=0
for i in range(rm+1):
  for j in range(bm+1):
    sa=n-r*i-b*j
    if sa<0:
      break
    elif sa%g==0:
      ans+=1
print(ans)

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

int main(){
   ll n,i,x,y,k,ans=0;
   cin>>n>>k>>x>>y;
   if(k>n) k=n;
   ans+=k*x;
   ans+=(n-k)*y;
   cout<<ans<<endl;
}




Measured memory_bytes: 3572
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;

int ord2(int m) { /*2で何回割り切れるかを返す*/
	if (m == 0) { return 0; }
	int ret = 0;
	while (m % 2 == 0) {
		m = m / 2;
		ret += 1;
	}
	return ret;
}

int N;
char S[1000001];
int a[1000000];

int main() {
	cin >> N;
	cin >> S;
	for (int i = 0; i < N; i++) {
		a[i] = S[i] - '1';
	}

	
	/*0と2しか出てこなかったら…*/
	bool all0or2 = true;
	for (int i = 0; i < N; i++) {
		if (a[i] == 1) { all0or2 = false; }
	}
	if (all0or2) {
		for (int i = 0; i < N; i++) {
			a[i] = a[i] / 2;
		}
	}

	/*偶奇を調べる*/
	/*C(N-1,j) % 2 == 1となるjだけ足せばよい。*/
	int cnt2 = 0;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (cnt2 == 0) {
			ans = ans + a[i];
			ans = ans % 2;
		}
		cnt2 = cnt2 + ord2(N - 1 - i) - ord2(i + 1);
	}

	if (all0or2) {
		cout << ans * 2;
	}
	else {
		cout << ans;
	}
	return 0;

}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(double a,double b){   return fabs(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}
ll setBit1(ll num, int idx) {return num | (1ll<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
int countNumBit1(ll mask) {int ret=0; while (mask) 	{mask &= (mask-1ll);++ret;	}return ret;}
int mem[100+9][100+9],n,m,arr[100+9][100+9];
int solve(int r,int c)
{

    if(c==m-1&&r==1)
    {
        return arr[r][c];
    }


    int &ret=mem[r][c];

    if(ret!=-1)
        return ret;



    int p1=0,p2=0;


    if(c+1<=m-1)
    p1=arr[r][c]+solve(r,c+1);
    if(r+1<=n-1)
    p2=arr[r][c]+solve(r+1,c);

    ret=max(p1,p2);

  return ret;
}

int main()
{
    cin>>m;

    n=2;

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

        }
    }
    clr(mem,-1);
    cout<<solve(0,0)<<endl;

}



Measured memory_bytes: 256
#include<iostream>
#include <vector>
using namespace std;
int main()
{
    int a;
    cin >> a;
    vector<string> cities;
    vector<int> values;
    vector<int> ids;
    for (int i = 0; i < a; ++i) {
      string b;
      int c;
      cin >> b;
      cin >> c;
      cities.push_back(b);
      values.push_back(c);
      ids.push_back(i);
    } 

    for (int i = 0; i < a; ++i) {
      for (int j = i; j < a; ++j) {
        if (cities[i] > cities[j]) {
          string temp = cities[i];
          cities[i] = cities[j];
          cities[j] = temp;
          int v = values[i];
          values[i] = values[j];
          values[j] = v;
          int e = ids[i];
          ids[i] = ids[j];
          ids[j] = e;
        } else if (cities[i] == cities[j]) {
          if (values[i] < values[j]) {
            string temp = cities[i];
            cities[i] = cities[j];
            cities[j] = temp;
            int v = values[i];
            values[i] = values[j];
            values[j] = v;
            int e = ids[i];
            ids[i] = ids[j];
            ids[j] = e;
          }
        }
      } 
    }
    for (int i = 0; i < a; ++i) {
      cout << ids[i] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String args[]) throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        int data = Integer.parseInt(reader.readLine());
         
        for(int i=1; i<=data; i++){
            if(i%3==0){
                builder.append(" ").append(Integer.toString(i));
                continue;
            }
            int x=i;
            do{
                if(x%10==3){
                    builder.append(" ").append(Integer.toString(i));
                    break;
                }
                x/=10;
            }while(x!=0);
        }
         
        System.out.println(builder);
         
    }
}

Measured memory_bytes: 20964
#include<iostream>
#include<vector>
#include<stack>
using namespace std;

struct tamari{
        int pos;
        int amount;
};

int main()
{
    stack<int> bs;
    vector<tamari> t;
    char c;
    int pos = -1;
    int sum = 0;
    while (cin >> c) {
        pos++;
        if (c == '\\') bs.push(pos);
        if (c == '/') {
            if (bs.empty()) continue;
            int rain = pos - bs.top();
            sum += rain;
            while (!t.empty() && bs.top() < t.back().pos) {
                rain += t.back().amount;
                t.pop_back();
            }
            bs.pop();
            tamari tmp;
            tmp.pos = pos;
            tmp.amount = rain;
            t.push_back(tmp);
        }
    }
    cout << sum << endl;
    cout << t.size();
    for (int i = 0; i < t.size(); i++) {
        cout << " " << t[i].amount;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3172
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	int32_t a, b, h;
	cin >> a >> b >> h;

	cout << (a + b )  * h / 2<< endl;

	return 0;
}


Measured memory_bytes: 256
from collections import*
class UnionFind():
    def __init__(self,size):
        self.table=[-1]*size
    def root(self,x):
        while self.table[x]>=0:
            x=self.table[x]
        return x
    def unite(self,x,y):
        s1=self.root(x)
        s2=self.root(y)
        if s1!=s2:
            if self.table[s1]>self.table[s2]:
                s1,s2=s2,s1
            self.table[s1]+=self.table[s2]
            self.table[s2]=s1
        return
    def same(self,x,y):
        return self.root(x)==self.root(y)
    def size(self,x):
        return -self.table[self.root(x)]
input=open(0).readline
n,k,l=map(int,input().split())
u=UnionFind(n)
v=UnionFind(n)
for _ in range(k):
    p,q=map(int,input().split())
    u.unite(p-1,q-1)
for _ in range(l):
    r,s=map(int,input().split())
    v.unite(r-1,s-1)
d=defaultdict(int)
a=[]
for i in range(n):
    t=(u.root(i),v.root(i))
    d[t]+=1
    a.append(t)
print(*[d[i]for i in a])

Measured memory_bytes: 99100
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			int k = sc.nextInt();
			if(n==0 && k==0) break;
			
			int[][] cost = new int[n+1][n+1];
			for(int i=1;i<=n;i++){
				Arrays.fill(cost[i], Integer.MAX_VALUE);
				cost[i][i] = 0;
			}
			
			int p, a, b ,c, d, e;
			for(int z=0;z<k;z++){
				p = sc.nextInt();
				if(p==0){
					a = sc.nextInt();
					b = sc.nextInt();
					if(cost[a][b]==Integer.MAX_VALUE) System.out.println(-1);
					else System.out.println(cost[a][b]);
				}else{
					c = sc.nextInt();
					d = sc.nextInt();
					e = sc.nextInt();
					if(e<cost[c][d]){
						cost[c][d] = e;
						cost[d][c] = e;
						for(int i=1;i<=n;i++){
							for(int j=1;j<=n;j++){	
								if(cost[i][c]!=Integer.MAX_VALUE && cost[d][j]!=Integer.MAX_VALUE){
									cost[i][j] = Math.min(cost[i][j], cost[i][c]+cost[c][d]+cost[d][j]);
								}
								if(cost[i][d]!=Integer.MAX_VALUE && cost[c][j]!=Integer.MAX_VALUE){
									cost[i][j] = Math.min(cost[i][j], cost[i][d]+cost[d][c]+cost[c][j]);
								}
								cost[j][i] = cost[i][j];
							}
						}
					}
				}
			}
		}	
	}	
}

Measured memory_bytes: 48836
#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll arr[100005];
int main()
{
    fast
    ll n,x,sum=0,q,a,b;
    cin >> n;
    for(ll i=1;i<=n;i++){
        cin >> x;
        sum+=x;
        arr[x]++;
    }
    cin >> q;
    while(q--){
        cin >> a >> b;
        sum+=(arr[a]*b - arr[a]*a);
        arr[b]+=arr[a];
        arr[a] = 0;
        cout << sum << endl;
    }
    return 0;
}



Measured memory_bytes: 4364
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int q[maxn];
char s[maxn];
int main()
{
	//std::ios::sync_with_stdio(false);
	int n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	scanf("%s",s);
	for(int i=0;i<n;i++)
	{
		if(s[i]=='#')q[i+1]=1;
		else q[i+1]=0;
	}
	if(c==d)
	{
		cout<<"No";
		return 0;
	}
	if(c<d)
	{
		for(int i=a;i<=d;i++)
		{
			if(q[i]==1&&q[i+1]==1)
			{
				cout<<"No";
				return 0;
			}
		}
	}
	else
	{
		int t=0;
		for(int i=b;i<=d;i++)
		{
			if(q[i]==0&&q[i-1]==0&&q[i+1]==0)
			{
				t=1;
				break;
			}
		}
		if(t==1)
		{
			for(int i=a;i<=c;i++)
			{
				if(q[i]==1&&q[i+1]==1)
				{
					cout<<"No";
					return 0;
				}
			}
		}
		else 
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 1152
A=[]
for _ in range(3):
    A+=map(int,input().split())

N=int(input())
for _ in range(N):
    b=int(input())
    if b in A:
        A[A.index(b)]=0

p=[
  (0,1,2),(3,4,5),(6,7,8),
  (0,3,6),(1,4,7),(2,5,8),
  (0,4,8),(2,4,6),
]

for i,j,k in p:
    if A[i]==A[j]==A[k]==0:
        print('Yes')
        break
else:
    print('No')


Measured memory_bytes: 61672
import sys
input = lambda: sys.stdin.readline().rstrip()

n,q=map(int,input().split())
a=list(map(int,input().split()))

num = 2**(n-1).bit_length()
def segfunc(x, y): return max(x, y)
seg = [0]*(2*num-1)
for i in range(n):
  seg[i+num-1] = a[i]
for i in range(num-2, -1, -1):
  seg[i] = segfunc(seg[2*i+1], seg[2*i+2])
def update(i, x):
  i += num-1
  seg[i] = x
  while i:
    i = (i-1)//2
    seg[i] = segfunc(seg[i*2+1], seg[i*2+2])
def query(l, r):
  l += num-1
  r += num-2
  if l == r:
    return seg[l]
  s = seg[l]
  l += 1
  while r-l > 1:
    if ~l % 2:
      s = segfunc(seg[l], s)
    if r % 2:
      s = segfunc(seg[r], s)
      r -= 1
    l //= 2
    r = (r-1)//2
  if l == r:
    return segfunc(s, seg[l])
  return segfunc(s, segfunc(seg[l], seg[r]))

for _ in range(q):
  t,a,b=map(int,input().split())
  if t==1:
    update(a-1,b)
  if t==2:
    print(query(a-1,b))
  if t==3:
    ng=a-1
    ok=n+1
    while ng+1!=ok:
      mid=(ng+ok)//2
      if query(ng,mid)>=b:ok=mid
      else:ng=mid
    print(ok)

Measured memory_bytes: 105460
import java.util.*;

public class Main {
  public static int C;
  public static ArrayList[] edge;
  public static HashMap[] map;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    edge = new ArrayList[n];
    map = new HashMap[n];
    for(int i = 0; i < n; i++) {
      edge[i] = new ArrayList<Integer>();
      map[i] = new HashMap<Integer, Integer>();
    }
    int[] a = new int[n - 1];
    int[] b = new int[n - 1];
    for(int i = 0; i < n - 1; i++) {
      a[i] = sc.nextInt() - 1;
      b[i] = sc.nextInt() - 1;
      edge[a[i]].add(b[i]);
      edge[b[i]].add(a[i]);
    }
    for(int i = 0; i < n; i++) {
      C = Math.max(C, edge[i].size());
    }
    Queue queue = new PriorityQueue<Integer>();
    queue.add(0);
    int[] seen = new int[n];
    seen[0] = 1;
    int[] co = new int[n];
    while(queue.size() > 0) {
      int v = (int)queue.poll();
      seen[v] = 1;
      ArrayList<Integer> e = edge[v];
      int pp = 1;
      for(int i = 0; i < e.size(); i++) {
        int u = e.get(i);
        if(seen[u] == 0) {
          if(pp == co[v]) pp++;
          map[v].put(u, pp);
          co[u] = pp;
          pp++;
          queue.add(u);
        }
      }
    }
    System.out.println(C);
    for(int i = 0; i < n - 1; i++) {
      System.out.println(map[a[i]].get(b[i]));
    }
  }
}

Measured memory_bytes: 106736