akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
X = read_int()

def solve():
    ans = float('INF')
    m = max(X)
    for i in range(1, m + 1):
        res = 0
        for x in X:
            res += (i - x) ** 2
        ans = min(res, ans)
    return ans

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

Measured memory_bytes: 3820
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int[] A = new int[N + 1];
            for (int i = 1; i <= N; i++) {
                A[i] = sc.nextInt();
            }

            int[] C = new int[N + 1];

            long ans = 1;

            for (int i = 1; i <= N; i++) {
                if (A[i] > 0) {
                    int c = C[A[i] - 1] - C[A[i]];

                    ans = ans * c % 1000000007L;
                }

                C[A[i]]++;
            }

            if (C[0] == 0 || C[0] > 3) {
                System.out.println(0);
                return;
            }

            if (C[0] == 1) {
                ans = ans * 3 % 1000000007L;
            } else {
                ans = ans * 6 % 1000000007L;
            }

            System.out.println(ans);
        }
    }

}


Measured memory_bytes: 50112
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

  function<double(double)> b2y = [](double b) {
    return b * 380000;
  };
    
  double ans = 0;
  REP(i, n){
    string x, u; cin >> x >> u;
    if(u == "JPY"){
      ans += stod(x);
    } else {
      ans += b2y(stod(x));
    }
  }

  cout << fixed << setprecision(5) << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
	int a,b,i=0,k,b1,b2;
	scanf("%d%d",&a,&b);
	b1=b;
	while(b1>0){
		b1=b1/10;
		i++;
	}
	 k=a*pow(10,i)+b;
	 b2=sqrt(k);
	 if(b2*b2==k) printf("Yes\n");
	 else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {
		long[][] memo;
		int N, C;
		int[][] d,c;
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			N = in.nextInt(); C = in.nextInt();
			d = new int[C][C];
			c = new int[N][N];

			for (int i = 0; i < C; i++) {
				for (int j = 0; j < C; j++) {
					d[i][j] = in.nextInt();
				}
			}

			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					c[i][j] = in.nextInt();
				}
			}

			memo = new long[3][C+1];
			for (int i = 0; i < 3; i++) {
				Arrays.fill(memo[i], -1);
			}

			long ans = Long.MAX_VALUE/2;
			for (int i = 1; i <= C; i++) {
				for (int j = 1; j <= C; j++) {
					for (int k = 1; k <= C; k++) {
						if (i == j || j == k || k == i) {
							continue;
						}
						ans = Math.min(ans, dfs(0, i) + dfs(1, j) + dfs(2, k));
					}
				}
			}

			out.println(ans);

		}

		long dfs(int mod, int to) {

			if (memo[mod][to] > 0) {
				return memo[mod][to];
			}

			int ret = 0;
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					if ((i+1 + j+1) % 3 == mod) {
						ret += d[c[i][j]-1][to-1];
					}
				}
			}

			return memo[mod][to] = ret;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 40924
/* ex4_3
   YSK722 */

#include <stdio.h>

// プロトタイプ宣言
int calculation(int name1, int name2);


int main(void){
    int west, east, ans;
    scanf("%d %d", &west, &east);

    // 関数の呼び出し
    ans = calculation(west, east);

    printf("%d\n", ans);
    return 0;
}


// 関数の定義
int calculation(int name1, int name2){
    int i, height = 0;
    for (i = 1; i < name2 - name1; i++) {
        height += i;
    }
    return height - name1;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import sys
from collections import Counter, defaultdict
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


class RollingHash():
    """
    Original code is https://tjkendev.github.io/procon-library/python/string/rolling_hash.html
    """
    class RH():
        def __init__(self, s, base, mod):
            self.base = base
            self.mod = mod
            self.rev = pow(base, mod-2, mod)

            l = len(s)
            self.h = h = [0]*(l+1)
            tmp = 0
            for i in range(l):
                num = s[i]
                tmp = (tmp*base + num) % mod
                h[i+1] = tmp

            self.pw = pw = [1]*(len(s)+1)
            v = 1
            for i in range(l):
                pw[i+1] = v = v * base % mod

        def calc(self, l, r):
            return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod

    @staticmethod
    def gen(a, b, num):
        result = set()
        while 1:
            import random
            import math
            random.seed()
            while 1:
                v = random.randint(a, b)//2*2+1
                if v not in result:
                    break
            for x in range(3, int(math.sqrt(v))+1, 2):
                if v % x == 0:
                    break
            else:
                result.add(v)
                if len(result) == num:
                    break
        return result

    def __init__(self, s, rand=False, num=5):
        if rand:
            bases = RollingHash.gen(2, 10**3, num)
        else:
            assert num <= 10
            bases = [641, 103, 661, 293, 547, 311, 29, 457, 613, 599][:num]

        MOD = 10**9+7
        self.rhs = [self.RH(s, b, MOD) for b in bases]

    def calc(self, l, r):
        return tuple(rh.calc(l, r) for rh in self.rhs)


def slv(N, A, B):
    a = []
    for i in range(N):
        a.append(A[i]^A[i-1])
    b = []
    for i in range(N):
        b.append(B[i]^B[i-1])
    b = b[:] + b[:]

    ah = RollingHash(a)
    bh = RollingHash(b)

    h = ah.calc(0, N)
    ans = []
    for k in range(N):
        if bh.calc(N-k, N-k+N) == h:
            ans.append('%d %d' % (k, A[0]^B[(N-k)%N]))


    return ans


def main():
    N = read_int()
    A = read_int_n()
    B = read_int_n()
    print(*slv(N, A, B), sep='\n')


if __name__ == '__main__':
    main()


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

typedef struct _place{
    int x,y;
}place;

//D 飛ばしの累積和を取ると良さげじゃない？
int main(void){
    int H,W,D;
    scanf("%d %d %d",&H,&W,&D);
    place p[H*W+1];
    int i,j,val;
    int p_sum[H*W+1];
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            scanf("%d ",&val);
            p[val].y = i+1;
            p[val].x = j+1;
        }
    }
    int now;
    for(i=0;i<H*W+1;i++){
        p_sum[i] = 0;
    }
    for(i=1;i<=D;i++){
        now=i;
        while(now+D<=H*W){//1 6 9 12とすると12-1としたい
            p_sum[now+D]+=p_sum[now] + abs(p[now+D].x-p[now].x)+abs(p[now+D].y-p[now].y);
            now += D;
        }
    }
    int Q;
    scanf("%d",&Q);
    int L[Q],R[Q];
    for(i=0;i<Q;i++){
        scanf("%d %d",&L[i],&R[i]);
    }
    int ans;
    for(i=0;i<Q;i++){
        ans = p_sum[R[i]]-p_sum[L[i]];
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 2816
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <bitset>
#include <cctype>
#include <fstream>
#include <numeric>
#include <utility>
#include <iomanip>
#include <complex>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;
int main()
{
    char a[7];
    scanf("%s",a);
    int k=strlen(a);
    int cnt=0;
    for(int i=0;i<k;i++)
    {
        if(a[i]=='1')
           cnt++;
    }
    printf("%d\n",cnt);
    return 0;

}




Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

enum MOD = (10 ^^ 9) + 7;

void main()
{
    long N, M, C;
    scan(N, M, C);
    auto B = aryread();
    long cnt;
    foreach (_; 0 .. N)
    {
        auto A = aryread();
        long sum;
        foreach (i, a; A)
        {
            sum += a * B[i];
        }
        sum += C;
        if (0 < sum)
        {
            cnt++;
        }
    }
    writeln(cnt);
}


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

typedef long long ll;
int arr[MAX];

int main()
{
    int n, cnt = 0;;

    scanf("%d", &n);
    ll sum = 0, Min = 1e12;
    for(int i = 1; i <= n; i++){
        scanf("%d",  &arr[i]);
        if(arr[i] < 0)
            cnt++;
        if(abs(arr[i]) < Min)
            Min = abs(arr[i]);
        sum += (ll) abs(arr[i]);
    }

    if(cnt % 2){
        sum -= 2 * Min;
    }
    printf("%lld\n", sum);

    return 0;
}


Measured memory_bytes: 640
//author : Anita Tasnim Proma (ICT,IU)
#include<bits/stdc++.h>
#define max 1e11+10
#define ll long long
using namespace std;

int main()
{    ll N;ll count=0;
    cin>>N;
    vector<ll>v(N);
     for(ll i=0;i<N;i++){
        cin>>v[i];
     }
     map<ll,ll>cnt;
     for(auto u:v) cnt[u]++;
     for(auto u:cnt){
        if(u.first<u.second){
            count+=(u.second-u.first);
        }
        else if(u.first>u.second){
            count+=u.second;
        }
        else if(u.first!=1 && u.second==1){
            count++;
        }

     }
     cout<<count<<endl;
}


Measured memory_bytes: 10016
S="012 345 678 036 147 258 048 246 "
A=sum([input().split()for i in range(3)],[])
for b in [input()for i in range(int(input()))]:
  if b in A:
    S=S.replace(str(A.index(b)),"")
print(["No","Yes"][S.find("  ")>-1])

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

int main(int argc, char* argv[]){
	int N;
	int F[102][12] = {0};
	int P[102][12] = {0};

	cin >> N;

	for(int i=1; i<=N; i++){
		for(int j=0; j<10; j++){
			cin >> F[i][j];
		}
	}
	for(int i=1; i<=N; i++){
		for(int j=0; j<=10; j++){
			cin >> P[i][j];
		}
	}

	long long ans = 0;
	for(int b=1; b < (1<<10); b++){
		long long ptot = 0;
		for(int i=1; i<=N; i++){
			int c = 0;
			for(int j=0; j<10; j++){
				int u = b & (1<<j);
				if(u !=0 && F[i][j] ==1){
					c++;
				}
			}
			ptot += P[i][c];
		}
		if(b==1){
			ans = ptot;
		}
		else if(ans < ptot){
			ans = ptot;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vout(v) VOUT(v,z);
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL);
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}

const string YES = "Yes";
const string NO = "No";
#define judge(f) cout<<(f?YES:NO)<<"\n";

void solve(long long K, long long X){
    bool f = 500*K>=X;
    judge(f);
}

int main(){
    long long K;
    scanf("%lld",&K);
    long long X;
    scanf("%lld",&X);
    solve(K, X);
    return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
#define For(i,l,r) for(int i = (l),i##end = (r);i <= i##end;i++)
#define Fordown(i,r,l) for(int i = (r),i##end = (l);i >= i##end;i--)
#define debug(x) cout << #x << " = " << x << endl
#define mp make_pair
#define fir first
#define sec second

using namespace std;

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

template <typename T> inline bool chkmin(T &x,T y) { return y < x ? x = y,1 : 0; }
template <typename T> inline bool chkmax(T &x,T y) { return x < y ? x = y,1 : 0; }

const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;

char str[N];

inline int read() {
	int x = 0,flag = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-')ch = getchar();
	if(ch == '-')flag = -1,ch = getchar();
	while(isdigit(ch))x = (x << 3) + (x << 1) + (ch - '0'),ch = getchar();
	return x * flag;
}

int main() {

	int n = read(),a = read(),b = read(),c = read(),d = read();
	scanf("%s",str + 1);
	int va = max(c,d),vb = min(c,d);
	For(i,a,va - 1) if(str[i] == '#' && str[i + 1] == '#') return puts("No"),0;
	if(c < d) return puts("Yes"),0;
	For(i,b - 1,vb - 1) if(str[i] == '.' && str[i + 1] == '.' && str[i + 2] == '.') return puts("Yes"),0;
	puts("No");
	return 0;
}

Measured memory_bytes: 384
program prob1
    implicit none
    integer::i, j, N, tmp, ans
    character(len=100)::S
    read(*,*) N
    read(*,*) S
    tmp = 0
    ans = 0
    do i = 1, N
        if(S(i:i) .eq. 'I') then
            tmp = tmp + 1
        else
            tmp = tmp - 1
        end if
        ans = max(ans, tmp)
    end do

    write(*,*) ans
    stop
end program

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

int main() {
	int H, W;
	cin >> H >> W;
	while (!(H == 0 && W == 0)) {
		for (int i = 0; i < W; i++) {
			cout << "#";
		}
		cout << endl;
		for (int j = 1; j < H - 1; j++) {
			cout << "#";
			for (int k = 1; k < W - 1; k++) {
				cout << ".";
			}
			cout << "#" << endl;
		}
		for (int l = 0; l < W; l++) {
			cout << "#";
		}
		cout << endl << endl;
		cin >> H >> W;
	}
	return 0;
}

Measured memory_bytes: 3092
/*
 * @Author: BilyHurington
 * @Date: 2020-03-08 20:00:46
 * @LastEditors: BilyHurington
 * @LastEditTime: 2020-03-08 20:02:20
 */
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<queue>
using namespace std;
int n;
char s[20];
int main(){
    scanf("%s",s+1);
    n=strlen(s+1);
    for(int i=1;i<=n;i+=2){
        if(s[i]!='h'||s[i+1]!='i'){printf("No\n");return 0;}
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*

*/
int main(){
  ll N,M,K; cin>>N>>M>>K;
  vector<ll> A(N+1,0),B(M+1,0);
  vector<ll> SA(N+1,0),SB(M+1,0);
  for(ll i=1; i<N+1; i++)cin>>A[i];
  for(ll i=1; i<M+1; i++)cin>>B[i];
  SA=A,SB=B;
  for(ll i=1; i<N; i++) SA[i+1]+=SA[i];
  for(ll i=1; i<M; i++) SB[i+1]+=SB[i];
  ll ans=0;
  rep(i,N+1){
    if(K-SA[i]<0) break;
    ll tmp=0;
    ll m=upper_bound(all(SB),K-SA[i])-SB.begin()-1;
    tmp=i+m;
    ans=max(tmp,ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 9544
n = int(input())
s = input()
# 左からi文字目までに存在するW,Eの累積和
east = [0] * (n + 1)
west = [0] * (n + 1)
for i in range(n):
    east[i + 1] = east[i]
    west[i + 1] = west[i]
    if s[i] == 'E':
        east[i + 1] += 1
    else:
        west[i + 1] += 1

ans = float('inf')
# 1番目がリーダー
ans = min(ans, east[-1] - east[2])
# 2~N-1番目
for i in range(2, n):
    tmp = west[i - 1] + east[-1] - east[i]
    ans = min(ans, tmp)
# N番目
ans = min(ans, west[n - 1])
print(ans)

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

//l-child, r-sibling representation

int n;
int p[100010], l[100010], r[100010];

void dfs(int n, int depth){
  if(p[n] == -1){
    cout << "depth = " << depth << ", ";
    return ;
  }

  dfs(p[n], depth + 1);
  return ;
}

void searchchild(int c){
  cout << '[';
  for(int i = 0;;i++){
    if(c == -1) break;
    cout << (i?", ":"");
    cout << c;
    c = r[c];
  }
  cout << ']' << endl;
}

void searchtype(int i){
  if(p[i] == -1) cout << "root, ";
  else if(l[i] != -1) cout << "internal node, ";
  else cout << "leaf, ";
}

void solve(){
  for(int i = 0;i < n;i++){
    cout << "node " << i << ": ";
    cout << "parent = " << p[i] << ", ";
    dfs(i, 0);
    searchtype(i);
    searchchild(l[i]);
  }
}

int main(){
  cin >> n;
  for(int i = 0;i < n;i++) p[i] = l[i] = r[i] = -1;
  for(int i = 0;i < n;i++){
    int id, k, c, s;

    cin >> id >> k;
    for(int j = 0;j < k;j++){
      cin >> c;
      if(j == 0) l[id] = c;
      else r[s] = c;
      p[c] = id;
      s = c;
    }
  }

  solve();

  return 0;
}



Measured memory_bytes: 4256
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, A, B;
  cin >> N >> A >> B;

  if (A > B) {
    cout << 0 << endl;
    return 0;
  }
  if (A == B) {
    cout << 1 << endl;
    return 0;
  }
  if (N == 1 && A != B) {
    cout << 0 << endl;
    return 0;
  }
  if (N == 1 || N == 2) {
    cout << 1 << endl;
    return 0;
  }

  cout << (B - A) * (N - 2) + 1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
    int n; cin >> n;
    int j=0;
    for(int i=1; i<2; i++){
        j += n*n;
    }
    cout << j*n;
}

Measured memory_bytes: 888
a,b,k=map(int,input().split())
if a+k>=b:
	for i in range(a,b+1):
		print(i)
	exit()
x=[i for i in range(a,a+k)]
y=[i for i in range(b-k+1,b+1)]
z=list(set(x+y))
z.sort()
for i in z:
	print(i)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;

int main()
{
    int X;
    cin >> X;
    if (X>=30)
        cout << "Yes" << endl;
    else    
        cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3620
#include <vector>
#include <iostream>
#include <cmath>
#include <utility>

using ll = long long;
using lli = long long int;

std::vector<std::pair<lli, lli>> prime_factor(lli n) {
    lli ex;
    std::vector<std::pair<lli, lli>> vec;
    for (lli i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            ex = 0;
            while (n % i == 0) {
                ex++;
                n /= i;
            }
            vec.push_back(std::make_pair(i, ex));
        }
    }
    if (n != 1) {
        vec.push_back(std::make_pair(n, 1));
    }
    return vec;
}


lli n, ans;
int main() {
    std::cin >> n;
    lli c = 0;
    auto primes = prime_factor(n);
    for (lli i = 0; i < primes.size(); i++) {
        lli f = primes[i].first;
        lli s = primes[i].second;
        //std::cout << "f=" << primes[i].first << "," << "s=" << primes[i].second << std::endl;
        if (n % f == 0) {
            lli t = f;
            while (n % f == 0) {
                n /= f;
                s--;
                c++;
                f *= t;
                if (s == 0) {
                    break;
                }
            }
        }

    }
    std::cout << c << std::endl;

}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<typename V> struct ConvexHull {
	deque<pair<V,V>> Q;
	int cmptype=1; // 0-min 1-max
	V calc(pair<V,V> p, V x) {
		return p.first*x+p.second;
	}
	int dodo(pair<V,V> A,pair<V,V> B, pair<V,V> C) { // max or min
		return cmptype^((B.second-C.second)*(B.first-A.first)<=(A.second-B.second)*(C.first-B.first));
	}
	void add(V a, V b) { // add ax+b
		Q.push_front({a,b});
		while(Q.size()>=3 && !dodo(Q[0],Q[1],Q[2]))
			Q[1]=Q[0], Q.pop_front();
	}
	V query(V x) {
		int L=-1,R=Q.size()-1;
		while(R-L>1) {
			int M=(L+R)/2;
			((cmptype^((calc(Q[M],x)>=calc(Q[M+1],x))))?L:R)=M;
		}
		return calc(Q[R],x);
	}
};


int N;
ll T[303030],LS[303030],RS[303030];
int M;
ConvexHull<ll> LC, RC;
ll LD[303030],RD[303030],inc[303030],ninc[303030];
ll tmemo[303030];

void dfs(int LL,int RR) {
	if(RR-LL<=1) return;
	int MM=(LL+RR)/2;
	dfs(LL,MM);
	dfs(MM,RR);
	
	ConvexHull<ll> TLC, TRC;
	TLC.add(0,0);
	TRC.add(0,0);
	int i,j;
	for(i=LL;i<RR;i++) {
		if(i<MM) TLC.add(-(i+1), 1LL*i*(i+1)/2 + LD[i+1] + LS[i+1]);
		else tmemo[i]=TLC.query(i+1) + 1LL*(i+1)*(i+2)/2 - LS[i+1]+RD[N-1-i];
	}
	for(j=RR-1;j>=LL;j--) {
		i=N-1-j;
		if(j>=MM) TRC.add(-(i+1), 1LL*i*(i+1)/2 + RD[i+1] + RS[i+1]);
		else tmemo[j]=TRC.query(i+1) + 1LL*(i+1)*(i+2)/2 - RS[i+1]+LD[j];
	}
	
	ll ma=-1LL<<60;
	for(i=RR-1;i>=MM;i--){
		ma=max(ma,tmemo[i]);
		inc[i]=max(inc[i],ma);
	}
	ma=-1LL<<60;
	for(i=LL;i<MM;i++){
		ma=max(ma,tmemo[i]);
		inc[i]=max(inc[i],ma);
	}
	
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>T[i];
	
	LC.add(0,0);
	RC.add(0,0);
	FOR(i,N) {
		LS[i+1]=LS[i]+T[i];
		LD[i+1]=max(LD[i], LC.query(i+1) + 1LL*(i+1)*(i+2)/2 - LS[i+1]);
		LC.add(-(i+1), 1LL*i*(i+1)/2 + LD[i+1] + LS[i+1]);
		
		RS[i+1]=RS[i]+T[N-1-i];
		RD[i+1]=max(RD[i], RC.query(i+1) + 1LL*(i+1)*(i+2)/2 - RS[i+1]);
		RC.add(-(i+1), 1LL*i*(i+1)/2 + RD[i+1] + RS[i+1]);
	}
	FOR(i,N) {
		ninc[i]=LD[i]+RD[N-1-i];
		inc[i]=1-T[i];
	}
	dfs(0,N);
	
	
	cin>>M;
	FOR(i,M) {
		cin>>x>>y;
		x--;
		cout<<max(ninc[x], inc[x] + T[x] - y)<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 21376
K = int(input())

def construct(K, N=50):
    As = [N+(K//N-1)-K%N]*50 # 50+K//50 - K%50
    q = K%N
    for q_ in range(q): As[q_] = N+K//N
    print(N)
    print(' '.join(map(str, As)))
    
construct(K)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <list>
 
using namespace std;
 
int main() {
	string s,last;
	cin >> s;
	last = s[s.size()-1];
	if(last == "s"){
	    cout << s << "es" << endl;
	}else{
	    cout << s << "s" << endl;
	}
	return 0;
}

Measured memory_bytes: 3596
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int n, k;
    cin >> n >> k;
    int h, ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> h;
        if (k <= h) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cmath>

#define REP(i,n) for(int (i) = 0;(i) < (n);(i)++)
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> N(n+1);
	REP(i,n) cin >> N[i+1];
	REP(i,n){
		cout << "node " << i+1 <<": key = " << N[i+1] << ", ";
		if((i+1)/2>0)cout << "parent key = " << N[(i+1)/2] << ", ";
		if(i*2+2<=n) cout << "left key = " << N[i*2+2] << ", ";
		if(i*2+3<=n) cout << "right key = " << N[i*2+3] << ", ";
		cout << endl;
	}
}

Measured memory_bytes: 3028
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

const MOD: i64 = 1_000_000_007;

fn main() {
    input! {
        n: usize,
        a: [usize; n]
    }

    // あり得るかを判定
    if a[0] != 0 {
        println!("-1");
        return;
    } else {
        let mut i = n - 1;
        while i >= 1 {
            if a[i - 1] as i64 >= a[i] as i64 - 1 {
                i -= 1;
                continue;
            } else {
                println!("-1");
                return;
            }
        }
    }

    let mut i = n - 1;
    let mut v = a[n - 1];
    let mut c = 0;
    while i >= 1 {
        if v <= a[i] {
            c += a[i];
        }
        v = a[i];
        i -= 1;
    }

    println!("{}", c);
}


Measured memory_bytes: 6396
#include <iostream>

int		get_scale(int power)
{
	int	scale;
	int	i;

	scale = 1;
	i = 0;
	while (i < power)
	{
		scale *= 10;
		++i;
	}
	return (scale);
}

bool	is_feasible(int n, int m, int *s, int *c, int num)
{
	int	i;

	i = 0;
	while (i < m)
	{
		if ((num / get_scale(n - s[i])) % 10 != c[i])
			return (false);
		++i;
	}
	return (true);
}

int	main()
{
	using namespace std;

	int		n;
	int		m;
	int		s[5];
	int		c[5];
	int		i;
	bool	found;
	int		upper;

	cin >> n >> m;
	i = 0;
	while (i < m)
	{
		cin >> s[i] >> c[i];
		++i;
	}
	i = (n == 1) ? 0 : get_scale(n - 1);
	found = false;
	upper = get_scale(n);
	while (i < upper)
	{
		if (is_feasible(n, m, s, c, i))
		{
			found = true;
			cout << i << endl;
			break;
		}
		++i;
	}
	if (!found)
		cout << -1 << endl;
	return (0);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mod 998244353
#define mad(a,b) a=(a+b)%mod
#define mul(a,b) a=a*b%mod
#define N 100010
ll cnt[N];
ll po(ll x,ll y){
    ll res=1;
    for(;y;y>>=1){
	if(y&1)mul(res,x);
	x=x*x%mod;
    }
    return res;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll n; cin>>n;
    for(int i=0;i<N;i++)cnt[i]=0;
    ll ma=0;
    for(int i=0;i<n;i++){
	ll d; cin>>d;
	chmax(ma,d);
	if(i==0&&d!=0){
	    cout<<0<<endl;
	    return 0;
	}
	if(i>0&&d==0){
	    cout<<0<<endl;
	    return 0;
	}
	cnt[d]++;
    }
    ll ans=1;
    for(int i=1;i<=ma;i++){
	mul(ans,po(cnt[i-1],cnt[i]));
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    int q; cin >> q;
    ll sum = 0;
    priority_queue<ll> front;
    priority_queue<ll, vector<ll>,greater<ll>> back;
    ll frontsum = 0;
    ll backsum = 0;
    rep(i,q){
        int type; cin >> type;
        if(type == 1){
            int a, b; cin >> a >> b;
            sum += b;
            if(front.size() > back.size()){
                int t = front.top();
                if(a >= t){
                    back.push(a);
                    backsum += a;
                }else{
                    front.pop(); frontsum -= t;
                    front.push(a); frontsum += a;
                    back.push(t); backsum += t;
                }
            }else{
                if(front.empty()) {
                    front.push(a); frontsum += a;
                }else{
                    int t = back.top();
                    if(t >= a){
                        front.push(a);
                        frontsum += a;
                    }else{
                        back.pop(); backsum -= t;
                        back.push(a); backsum += a;
                        front.push(t); frontsum += t;
                    }
                }
            }
        }else{
            ll x = front.top();//常に同数かfrontが１つ多い
            ll res = x*(int)front.size() - frontsum + backsum - x*(int)back.size() + sum;
            cout << x << " " << res << endl;
        }
    }
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b, c;
	cin >> a >> b >> c;
	if (c <= a + b) {
		cout << b+c << endl;
	}
	else {
		cout << a + b + 1 + b << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int k;
    cin >> k;
    string str;
    cin >> str;
    
    if(str.length()<=k)
        cout << str;
        else
        {
         for(int i=0;i<k;i++)
             cout << str[i];
             cout << "...";
        }
        return 0;
}

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

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back

using namespace std;

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

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int a;
  string s;
  cin >> a >> s;
  if (a < 3200) cout << "red" << endl;
  else cout << s << endl;
  return (0);
}


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

int main() {
    int n;
    int a[100000];
    cin >> n;
    for(int i=0; i<n; ++i) cin >> a[i];
    
    long long ans1 = 0;
    long long sum = a[0];
    if(sum <= 0) {
        ans1 += abs(sum) + 1;
        sum = 1;
    }
    for(int i=1; i<n; ++i) {
        if((sum > 0 && sum + a[i] >= 0) || (sum < 0 && sum + a[i] <= 0)) {
            ans1 += abs(sum + a[i]) + 1;
            if(sum > 0) sum = -1;
            else sum = 1;
        } else {
            sum += a[i];
        }
    }

    long long ans2 = 0;
    sum = a[0];
    if(sum >= 0) {
        ans2 += abs(sum) + 1;
        sum = -1;
    }
    
    for(int i=1; i<n; ++i) {
        if((sum > 0 && sum + a[i] >= 0) || (sum < 0 && sum + a[i] <= 0)) {
            ans2 += abs(sum + a[i]) + 1;
            if(sum > 0) sum = -1;
            else sum = 1;
        } else {
            sum += a[i];
        }
    }
    cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  ll W,H,X,Y; cin >>W>>H>>X>>Y;
  double s = (double) W*H/2LL;
  bool ok = X*2==W&&Y*2==H;
  printf("%.10f %d\n", s, ok);
  
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
 
N = int(input())
AB = [[int(i) for i in input().split()] for _ in range(N-1)]

# graph[i]: 頂点iの親と子の集合
graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

# 根
root = 1
# parent[i]: 頂点iの親
parent = [0]*(N+1)
# トポロジカル順序(dfsの順番)
order = []
# 未探索の頂点
stack = [root]

# dfsでparentを求める
while stack:
    # n: 探索する頂点
    n = stack.pop()
    order.append(n)
    for j in graph[n]:
        # jがnの親の場合
        if j == parent[n]:
            continue
        parent[j] = n
        stack.append(j)

# color[i]: 頂点iと親を繋ぐ辺の色
color = [-1] * (N+1)
# dfsで頂点iから出る辺の色を塗る
for i in order:
    # 既に使用した色
    ng = color[i]
    # 色
    c = 1
    for j in graph[i]:
        # jがiの親の場合(塗装済みなのでcontinue)
        if j == parent[i]:
            continue
        if c == ng:
            c += 1
        # 頂点iと頂点jの辺に色を塗る
        color[j] = c
        c += 1

# 入力順に辺の色を出力する
answer = [color[a] if parent[a]==b else color[b] for a,b in AB]
print(max(answer))
print("\n".join(map(str,answer)))

Measured memory_bytes: 42844
#include <stdio.h>
#include <string.h>

int main()
{
	int n, m;
	int h[105];
	int target[100];
	int cnt[105] = { 0 };
	int i, j;
	scanf("%d%d", &n, &m);
	for (i = 0;i < m;i++) {
		scanf("%d", &target[i]);
	}
	for(i=0;i<m;i++){
	for (j = 1;j <= n;j++){
			scanf("%d", &h[j]);
			if (h[j] == target[i])cnt[j] += 1;
			else cnt[target[i]] += 1;
		}
	}
	for (i = 1;i <= n;i++) {
		printf("%d\n", cnt[i]);
	}
	return 0;
}

Measured memory_bytes: 596
/* Filename: AGC020A.java
 * Author: Mushiyo
 */

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		
		while(input.hasNext()){
			int N = input.nextInt();
			int A = input.nextInt();
			int B = input.nextInt();
			
			if((B - A + 1) % 2 == 1){
				System.out.println("Alice");
			} else {
				System.out.println("Borys");
			}
		}
	}

}


Measured memory_bytes: 20948
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  if(c =='a' ||c =='i' ||c =='u' ||c =='e' ||c =='o' ) {
cout << "vowel" << endl;
}else{
cout << "consonant" << endl;
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll mod=1e9+7;

ll facctorialMethod(ll k){
	ll sum=1;
	for (ll i=1;i<=k;++i)
	{
		sum*=i;
		sum=sum%mod;
	}
	return sum;
}

int main(){
	ll N,M;cin>>N>>M;
	if (abs(N-M)>1){
		cout << 0 << endl;
		exit(0);
	}
	ll temp=(facctorialMethod(N)*facctorialMethod(M))%mod;
	ll ret=N==M?(temp*2)%mod:temp;
	cout<<ret<<endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
ll X[int(1e5 + 5)], Y[int(1e5 + 5)];
Pli PX[int(1e5 + 5)], PY[int(1e5 + 5)];

vector <Pil> Graph[int(1e5 + 5)];
ll Dist[int(1e5 + 5)];

int main(){
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%lld%lld", X + i, Y + i);
    PX[i] = {X[i], i};
    PY[i] = {Y[i], i};
  }
  sort(PX, PX + N); sort(PY, PY + N);

  for (int i = 0; i < N - 1; i++){
    ll now = PX[i + 1].fi - PX[i].fi;
    Graph[PX[i].se].push_back({now, PX[i + 1].se});
    Graph[PX[i + 1].se].push_back({now, PX[i].se});
  }
  for (int i = 0; i < N - 1; i++){
    ll now = PY[i + 1].fi - PY[i].fi;
    Graph[PY[i].se].push_back({now, PY[i + 1].se});
    Graph[PY[i + 1].se].push_back({now, PY[i].se});
  }

  fill(Dist, Dist + N + 1, -1);
  priority_queue <Pli, vector<Pli>, greater<Pli> > que;
  Dist[0] = 0;
  for (int i = 0; i < Graph[0].size(); i++) que.push(Graph[0][i]);

  ll ans = 0;
  while (!que.empty()){
    Pli Q = que.top(); que.pop();
    if (Dist[Q.se] != -1) continue;
    Dist[Q.se] = Q.fi;
    ans += Q.fi;

    for (int i = 0; i < Graph[Q.se].size(); i++){
      int next = Graph[Q.se][i].se;
      if (Dist[next] != -1) continue;

      que.push(Graph[Q.se][i]);
    }
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 22204
#include <bits/stdc++.h>
#define ll long long
const ll base = 31;
const ll MOD = 1e9+9;
const ll  maxN = 1e6+9;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std ;
int main()
{   ios_base::sync_with_stdio(0) ;
    cin.tie(0);
    cout.tie(0);
    string a;
    deque<char>s;
  cin >> a ;
  for ( int i = 0; i<a.size(); i++)
    s.push_back(a[i]) ;
  char k ;
  int q ,x ,y , cnt = 0;
  cin >> q;
  while(q--)
  { cin >> x;
    if ( x ==1) cnt++;
     else {
        cin >> y >> k ;
    if ( y == 1){
            if ( cnt % 2==1) s.push_back(k);
            else s.push_front(k);
     }
    else {
            if ( cnt % 2 ==0)s.push_back(k);
            else s.push_front(k);

  }
  }
  }
  if ( cnt % 2 ==1)
  { while( !s.empty()){
      k = s.back() ;
      s.pop_back();
      cout<<k;
  }
  }
   else{
    while (! s.empty() ){
        k = s.front();
    s.pop_front();
    cout<<k;
   }
}
}


Measured memory_bytes: 976
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// AtCoder_D
		Scanner sc = new Scanner(System.in);

		long N = sc.nextLong();

		long ans = (N-1)*N/2;

		System.out.println(ans);

	    // Scannerクラスのインスタンスをクローズ
		sc.close();
	}
}


Measured memory_bytes: 35580
#include"bits/stdc++.h"

void Main() {
  int a, b;
  std::cin >> a >> b;

  int r = a - b * 2;
  if (r < 0) {
    std::cout << 0 << std::endl;
  } else {
    std:: cout << r << std::endl;
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    set<int> s;
    int wild = 0;
    rep(i, n) {
        int a; cin >> a;
        if (a < 400) s.insert(0);
        else if (a < 800) s.insert(1);
        else if (a < 1200) s.insert(2);
        else if (a < 1600) s.insert(3);
        else if (a < 2000) s.insert(4);
        else if (a < 2400) s.insert(5);
        else if (a < 2800) s.insert(6);
        else if (a < 3200) s.insert(7);
        else wild++;
    }
    if (wild != 0) {
        int tmp = s.size();
        (tmp==0) ? cout << 1 << " " : cout << tmp << " ";
        chmax(tmp, tmp+wild);
        cout << tmp << endl;
    } else {
        cout << (int)s.size() << " "  << (int)s.size() << endl;
    }

    return 0;
}

Measured memory_bytes: 256