akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)    FOR (i,0,n)
#define ALL(f,x,...) ([&](decltype((x)) ALL) {                          \
            return (f)(begin(ALL), end(ALL), ## __VA_ARGS__); })(x)

using namespace std;
using ll = int64_t;

const string YES = "YES";
const string NO = "NO";

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

    bool flg = false;

    ll dif = B - A;

    // A から N - 1 回の加算のうち
    // 正の C D の条件を満たすものが i 個存在する
    REP(i, N)
    {
        // 正
        // i * C <= (正の差分) <= i * D
        ll pl = i * C;
        ll pu = i * D;

        // 負
        // (N - 1 - i) * (-D) <= (負の差分) <= (N - 1 - i) * (-C)
        ll nl = (N - 1 - i) * (-D);
        ll nu = (N - 1 - i) * (-C);

        // 正負を含めた 下限 AND 上限
        if ((pl + nl <= dif) && (dif <= pu + nu))
        {
            flg = true;
            break;
        }
    }

    cout << (flg ? YES : NO) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	  public static int Compute_maxprofit(int[] R, int n) {
		  int maxProfit = Integer.MIN_VALUE; 
		  int min = R[0];
	
		  for(int i = 1; i < n; i++) {
			  if(maxProfit < R[i]-min) maxProfit = R[i]-min;
			  if(min>R[i]) min = R[i];
		  }
		  return maxProfit;
	  }
	  
	  public static void main(String[] args) {
		  Scanner in = new Scanner(System.in);
		  int n = in.nextInt();		
		  int[] R = new int[n];
		
		  for(int i = 0; i<n; i++) {
			  R[i]=in.nextInt();
		  }
		
		  System.out.println(Compute_maxprofit(R,n));
		
	  }

}


Measured memory_bytes: 102036
#include<iostream>

using namespace std;

int main(){
    int n, mn=50;
    cin >> n;
    for(int i=0;i<n;i++){
        long long tmp;
        cin >> tmp;
        int cnt=0;
        while(tmp%2==0){
            tmp/=2;
            cnt++;
        }
        mn = min(cnt, mn);
    }
    cout << mn << endl;
}

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

using namespace std;

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

    int stones[n];
    int dp[n] = { 0 };
    for (int i = 0; i < n; i++)
    {
        cin >> stones[i];
    }
    
    dp[1] = abs(stones[1] - stones[0]);
    for (int i = 2; i < n; i++)
    {
        dp[i] = min(abs(stones[i] - stones[i - 1]) + dp[i - 1], abs(stones[i] - stones[i - 2]) + dp[i - 2]);
    }

    cout << dp[n - 1];
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct Sieve {
    Sieve(int n) : l(n + 1, 0) {
        for (int i = 2; i <= n; i++) {
            if (!l[i]) p.push_back(l[i] = i);
            for (int q : p) {
                if (q > l[i]) break;
                if (int j = i * q; j <= n) l[j] = q; else break;
            }
        }
    }
    bool is_prime(int i) {
        return l[i] == i;
    }
    vector<int> l, p;
};

constexpr int M = (int)1e+6;

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

    int n;
    cin >> n;

    vector<int> a(n), b(M + 1, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[a[i]]++;
    }

    Sieve si(M);
    for (int p : si.p) {
        for (int j = 1; j * p <= M; j++) {
            b[j * p] += b[j];
        }
    }

    int r = 0;
    for (int i = 0; i < n; i++) {
        r += b[a[i]] == 1;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 12484
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string s;
  cin >> s;
  if (s == "AAA" || s == "BBB")
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

Measured memory_bytes: 3584
n = int(input())
if n ==0:
    print(0)
else:
    res = []
    while n != 0:
        if n % 2 == 1:
            res.append("1")
        else:
            res.append("0")
        n = (n-n%2) // -2
    res = res[::-1]
    print("".join(res))


Measured memory_bytes: 61664
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cassert>
#include <cstring>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

int a[100000];

int main(void) {
    int i, n;
    scanf("%d",&n);
    REP (i,n) scanf("%d",&a[i]);

    long long ans = 0;
    long long mx = 0;
    map<int,int> mp;
    REP (i,n) mp[a[i]]++;
    REP (i,n) if (mp[a[i]] >= 2) {
        ans = max(ans,mx * a[i]);
        mx = max<int>(mx,a[i]);
        mp[a[i]] -= 2;
    }
    printf("%lld\n",ans);
    return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A []= new int[3];
		for (int i=0;i<3;i++) {
			A[i]= sc.nextInt();
		}
		Arrays.parallelSort(A);
		if (A[0]==A[1]&&A[1]==5&&A[2]==7) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    char a; cin >> a;
    if('a' <= a && a <= 'z') cout << 'a' << endl;
    else cout << 'A' << endl;
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 3624
#include <stdio.h>

int main(void){
   int k,x,total;
   if(scanf("%d%d",&k,&x)>3){return -1;}
   total = 500 * k;
   
   if (total>=x){
      printf("Yes");
   } else {
      printf("No");                                                             
   }
   return 0;
}

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

int h(int a){
  int ans = 0;
  while(a > 0){
    ans += a % 10;
    a /= 10;
    if(!a > 0) return ans;
  }
}

int main(){
  int n;
  cin >> n;
  if(n % h(n) == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3540
import java.io.*;

public class Main{
    public static void main(String[] args)throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder st = new StringBuilder();
        
        int k = 0;
        
        while(true){
            int num = Integer.parseInt(br.readLine());
            
            if(num == 0){
            break;
            }

            k++;
            String Ans ="Case " + k +": " + num; 
            System.out.println(Ans);
        }
    }
}

Measured memory_bytes: 31364
from collections import Counter
S = input()
ctr = Counter(S)

if len(ctr) == 1:
    print('YES' if len(S) == 1 else 'NO')
elif len(ctr) == 2:
    print('YES' if len(S) == 2 else 'NO')
else:
    mx = max(ctr.values())
    mn = min(ctr.values())
    print('YES' if mx-mn < 2 else 'NO')


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
#define YesNo(a) cout<<((a)?"Yes":"No")<<endl;
#define YESNO(a) cout<<((a)?"YES":"NO")<<endl;

int main(){
	ll H,W,A,B;
	cin >> H >> W >> A >> B;

	FOR(i,0,H){
		FOR(j,0,W){
			if((i<B&&j<A)||(i>=B&&j>=A)){
				cout << 0;
			}else{
				cout << 1;
			}
		}
		cout << endl;
	}
}

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

int main() {
  int x;
  cin >> x;
  if(x == 3 || x == 5 || x == 7){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
unittest
{
	assert( [ "4" ].parse.expand.solve == 1 );
	assert( [ "999999" ].parse.expand.solve == 499999 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	return tuple( n );
}

auto solve( long n )
{
	return n / 2 - ( n % 2 == 0 );
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n,k,l[9];
    cin>>n>>k;
    for(int i=0;i<k;i++){
        cin>>l[i];
    }
    for(int i=n;i<100000;i++){
        int a,b,c,d,e;
        a = i/10000;
        b =(i%10000)/1000;
        c =(i%1000)/100;
        d =(i%100)/10;
        e = i%10;
        if(i<10000)a=-1;
        if(i<1000)b=-1;
        if(i<100)c=-1;
        if(i<10)d=-1;
        bool hoge = true;
        for(int j=0;j<k;j++){
            if(a==l[j]||b==l[j]||c==l[j]||d==l[j]||e==l[j]){
                hoge = false;
            }
        }
        if(hoge){
            n=i;
            i=100000;
        }
    }
    cout<<n<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
int n;
string a, b;
string solve(string b) {
	for (int i = 1; i<n - 1; i++) {

		if (b[i] == 'S') {
			if (a[i] == 'x') {
				if (b[i - 1] == 'S')
					b[i + 1] = 'W';
				else
					b[i + 1] = 'S';
			}
			else {
				if (b[i - 1] == 'S')
					b[i + 1] = 'S';
				else
					b[i + 1] = 'W';
			}
		}
		else {
			if (a[i] == 'x') {
				if (b[i - 1] == 'S')
					b[i + 1] = 'S';
				else
					b[i + 1] = 'W';
			}
			else {
				if (b[i - 1] == 'S')
					b[i + 1] = 'W';
				else
					b[i + 1] = 'S';
			}
		}
	}
	return b;
}
int rep(int a) {
	if (a == n)
		return 0;
	if (a == -1)
		return n - 1;
	return a;
}
bool l(string b) {
	for (int i = 0; i < n; i++) {
		if (b[i] == 'S') {
			if (a[i] == 'o') {
				if (b[rep(i - 1)] != b[rep(i + 1)])
					return 0;
			}
			else {
				if (b[rep(i - 1)] == b[rep(i + 1)])
					return 0;
			}
		}
		else {
			if (a[i] == 'o') {
				if (b[rep(i - 1)] == b[rep(i + 1)])
					return 0;
			}
			else {
				if (b[rep(i - 1)] != b[rep(i + 1)])
					return 0;
			}
		}
	}
	return 1;
}
int main() {
	cin >> n >> a;
	b = "";
	for (int i = 0; i < n; i++)
		b += 'K';
	b[0] = 'S';
	b[1] = 'S';
	b = solve(b);
	if (l(b)) {
		cout << b << endl;
		goto stop;
	}
	b[1] = 'W';
	b = solve(b);
	if (l(b)) {
		cout << b << endl;
		goto stop;
	}
	b[0] = 'W';
	b[1] = 'S';
	b = solve(b);
	if (l(b)) {
		cout << b << endl;
		goto stop;
	}
	b[1] = 'W';
	b = solve(b);
	if (l(b)) {
		cout << b << endl;
		goto stop;
	}
	cout << -1 << endl;
stop:;
	cin >> n;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
int main(){
  long a[3000],ans=0,b=1;
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%ld",&a[i]);
    ans+=a[i]-1;
  }
  printf("%ld\n",ans);
}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    int n=gi();
        int[] A=new int[n];
        
        for(int i=0; i<n;i++) {
        	A[i]=gi();
        }
        
        Arrays.parallelSort(A);
	   
	    System.out.print(A[A.length-1]-A[0]);

//        if (t.equals("Sunny")) {
//        	System.out.print("Cloudy");
//        }else if(t.equals("Cloudy")){
//        	System.out.print("Rainy");
//        } else {
//        	System.out.print("Sunny");
//        }


	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35680
#include<stdio.h>

int main(){
  int a[3];
  scanf("%d",&a[0]);
  scanf("%d",&a[1]);
  scanf("%d",&a[2]);

  if(a[0] <= a[1] && a[0] <= a[2]){
    if(a[1]<=a[2])
      printf("%d\n",a[2]-a[0]);
    else if(a[1]>a[2])
      printf("%d\n",a[1]-a[0]);
    return 0;
  }
  if(a[1] <= a[0] && a[1] <= a[2]){
    if(a[0]<=a[2])
      printf("%d\n",a[2]-a[1]);
    else if(a[0]>a[2])
      printf("%d\n",a[0]-a[1]);
    return 0;
  }
  if(a[2] <= a[0] && a[2] <= a[1]){
    if(a[0]<=a[1])
      printf("%d\n",a[1]-a[2]);
    else if(a[0]>a[1])
      printf("%d\n",a[0]-a[2]);
    return 0;
  }
}

Measured memory_bytes: 128
from collections import Counter
from functools import reduce
import fractions
import math
import sys
import statistics
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  # greatest common divisor
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  # least common multiple
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


N = II()
a = LI()
ai = [a[i-1] - i for i in range(1, N+1)]
b = round(statistics.median(ai))
print(sum([abs(b - ai[i]) for i in range(len(ai))]))


Measured memory_bytes: 29508
from operator import mul
from functools import reduce


def comb(n, r):
    r = min(n-r,r)
    if r == 0:
      return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

  
n, k = map(int, input().split())
for i in range(1, k+1):
	if n-k+1 >= i:
		cnt = comb(n-k+1, i) * comb(k-1, i-1)
		print(cnt%(10**9+7))
	else:
		print(0)


Measured memory_bytes: 4200
n,k=map(int,input().split())
x=sorted(list(map(int,input().split())))
a=[]
for i in range(n-k+1):
    l=x[i]
    r=x[i+k-1]
    a.append(min(abs(l)+abs(r-l),abs(r)+abs(l-r)))
print(min(a))

Measured memory_bytes: 14252
using System;

public class FiftyFifty{
    public static void Main(string[] argc){
        string input = Console.ReadLine();
        bool isFiftyFifty = IsAFiftyFifty(input);
        Console.WriteLine(isFiftyFifty ? "Yes" : "No");
    }

    public static bool IsAFiftyFifty(string inputStr) {
        char? first = null;
        char? second  = null;
        int firstNum = 0;
        int secondNum = 0;
        foreach (char alphabate in inputStr)
        {
            if(first == null){
                first = alphabate;
            }else if(second == null && first != alphabate){
                second = alphabate;
            }else if(first == alphabate){
                firstNum += 1;
            }else if(second == alphabate)
            {
                secondNum += 1;
            }else{
                return false;
            }
        }
        if(firstNum == 1 && secondNum == 1){
            return true;
        }
        return false;
    }
}

Measured memory_bytes: 11220
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX_N = 50;
int N, A;
int x[MAX_N+1];
ll dp[MAX_N+1][MAX_N+1][MAX_N*MAX_N+1];

int main() {
  cin >> N >> A;
  for (int i = 1; i <= N; ++i) cin >> x[i];

  for (int i = 0; i <= N; ++i) dp[i][0][0] = 1;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= i; ++j) {
      for (int k = 1; k <= j*50; ++k) {
        dp[i][j][k] = dp[i-1][j][k];
        if (k >= x[i]) dp[i][j][k] += dp[i-1][j-1][k-x[i]];
      }
    }
  }

  ll ans = 0;
  for (int j = 1; j <= N; ++j) {
    ans += dp[N][j][j*A];
  }

  cout << ans << endl;

  return 0;
}


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

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

  int a, b, c;
  cin >> a >> b >> c;
  cout << c << " " << a << " " << b << endl;
  
  return 0;
}

Measured memory_bytes: 256
A,B,M=map(int,input().split())

a=list(map(int,input().split()))
b=list(map(int,input().split()))

minc=min(a)+min(b)

for i in range(M):
  x,y,c=map(int,input().split())
  cash=a[x-1]+b[y-1]-c

  if cash<minc:
    minc=cash

print(minc)

Measured memory_bytes: 70340
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using ll = long long;
using ull = unsigned long long;

using namespace std;

int main(int argc, char const *argv[]) {
	int n;
	std::cin >> n;
	std::vector<ll> a(n),b(n);
	for (size_t i = 0; i < n; i++) {
		std::cin >> a[i];
		b[i] = a[i] - i;
	}
	sort(b.begin(),b.end());
	ll ans1,ans2;
	ans1 = ans2 = 0;
	int plus1 = b[b.size() / 2];
	int plus2 = b[b.size() / 2 + 1];

	for (int i = 0; i < a.size(); i++) {
		ans1 += abs(a[i] - i - plus1);
		ans2 += abs(a[i] - i - plus2);
	}

	std::cout << min(ans1, ans2) << '\n';
	return 0;
}


Measured memory_bytes: 3328
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;
vector<int> edge[100001];
int ans[100001];
int n, m;
void adde()
{
  int from, to;
  cin >> from >> to;
  edge[to].emplace_back(from);
  edge[from].emplace_back(to);
}
bool bfs()
{
  queue<int> qu;
  qu.push(1);
  ans[1] = -1;
  while (!qu.empty())
  {
    int t = qu.front();
    qu.pop();
    for (int i : edge[t])
    {
      if (ans[i] != 0)
        continue;
      ans[i] = t;
      qu.push(i);
    }
  }
  for (int i = 2; i <= n; ++i)
    if (ans[i] == 0)
      return false;
  return true;
}
int main()
{
  // freopen("in", "r", stdin);
  cin >> n >> m;
  for (int i = 0; i < m; ++i)
    adde();
  if (bfs())
  {
    cout << "Yes\n";
    for (int i = 2; i <= n; ++i)
      cout << ans[i] << '\n';
  }
  else
    cout << "No\n";
  return 0;
}

Measured memory_bytes: 10388
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> E(N);
  for (int i = 0; i < M; i++){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    E[a].push_back(b);
    E[b].push_back(a);
  }
  vector<int> deg(N);
  for (int i = 0; i < N; i++){
    deg[i] = E[i].size();
  }
  sort(deg.begin(), deg.end());
  reverse(deg.begin(), deg.end());
  bool ok = true;
  for (int i = 0; i < N; i++){
    if (deg[i] % 2 == 1){
      ok = false;
    }
  }
  if (!ok){
    cout << "No" << endl;
  } else {
    if (deg[0] == 2){
      cout << "No" << endl;
    } else if (deg[0] >= 6){
      cout << "Yes" << endl;
    } else if (deg[0] == 4){
      if (deg[1] == 2){
        cout << "No" << endl;
      } else if (deg[2] == 4){
        cout << "Yes" << endl;
      } else {
        int s = -1;
        for (int i = 0; i < N; i++){
          if (E[i].size() == 4){
            s = i;
          }
        }
        vector<bool> used(N, false);
        int t = 0;
        if (s == t){
          t++;
        }
        used[t] = 0;
        queue<int> Q;
        Q.push(t);
        while (!Q.empty()){
          int v = Q.front();
          Q.pop();
          for (int w : E[v]){
            if (w != s && !used[w]){
              used[w] = true;
              Q.push(w);
            }
          }
        }
        ok = false;
        for (int i = 0; i < N; i++){
          if (!used[i] && i != s){
            ok = true;
          }
        }
        if (ok){
          cout << "Yes" << endl;
        } else {
          cout << "No" << endl;
        }
      }
    }
  }
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

int main() {
    int H, N; cin >> H >> N;
    vint A(N), B(N);
    for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
    vint dp(100000, INF);
    dp[0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < H; j++) {
            chmin(dp[j + A[i]], dp[j] + B[i]);
        }
    }
    ll minv = INF;
    for (int i = H; i < 100000; i++) {
        chmin(minv, dp[i]);
    }
    cout << minv << endl;
    return (0);
}

Measured memory_bytes: 640
from copy import deepcopy
n = int(input())
b1 = [[0]*10,[0]*10,[0]*10]
b2 = deepcopy(b1)
b3 = deepcopy(b1)
b4 = deepcopy(b1)
answer = [b1,b2,b3,b4]
for i in range(n):
	b,f,r,v = map(int,input().split())
	answer[b-1][f-1][r-1] += v
counter = 0
for k in answer:
	for kk in k:
		kk = list(map(str,kk))
		print(" "," ".join(kk),sep="")
	counter += 1
	if counter != 4:
		print("#"*20)


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

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

int main()
{
    int A, B, H, M;
    cin >> A >> B >> H >> M;
    double shita = abs(((double)H * 30.0 + ((double)M * 30.0)/ 60.0) - (double)M * 6.0);
    shita = min(shita, 360.0 - shita);
    double ans = sqrt((double)A * (double)A + (double)B * (double)B - 2.0 * (double)A * (double)B * cos(M_PI / 180 * shita));
    printf("%.20f\n", ans);
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3
#define mod 1000000007LL

ll mod_pow(ll x,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*x%mod;
    x=x*x%mod;
    n>>=1;
  }
  return res%mod;
}

ll h,w,k;
ll fact[311111],finv[311111];

ll comb(ll n,ll r){
  if(r<0||n<r)return 0;
  return ((fact[n]*finv[n-r])%mod)*finv[r]%mod;
}

int main(){
	cin.sync_with_stdio(false);
  fact[0]=fact[1]=1;
  repl(i,1,301010)fact[i+1]=fact[i]*(i+1)%mod;
  rep(i,301010)finv[i]=mod_pow(fact[i],mod-2);
  cin>>w>>h>>k;
  ll res=0;
  rep(i,k+1){
    ll j=k-i;
    res=(res+(((comb(2*i+w,i)-comb(2*i+w,i-1)+mod)%mod)*((comb(2*j+h,j)-comb(2*j+h,j-1)+mod)%mod)%mod)*(comb(w+h+2*i+2*j,w+2*i)))%mod;
  }
  cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 7908
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
  cin>>n;
  for (int i=1;i<=9;i++)
  {
    if (n%i==0 and n/i>=1 and n/i<=9)
      return cout << "Yes", 0; 
    else
      continue;
  }
  cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int a[6];
    rep(i, 5){
        cin >> a[i];
    }
    
    int k;
    cin >> k;
    
    string s = "Yay!";
    sort(a, a+5);
    if(a[4]-a[0] > k)  s = ":(";
    
    cout << s << endl;
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<ll>a(n);
	for (int i = 0; i < n; i++)cin >> a.at(i);
	ll l = -1;
	ll r = a.at(0) * 2+1;
	vector<ll>ans(n);
	while (r - 1 > l) {
		vector<ll>ac = a;
		ll mid = (r + l) / 2;
		mid *= 2;
		//cout << "mid:" << mid << " l:" << l << " r:" << r << endl;
		ac.at(0) -= mid / 2;
		ac.at(n - 1) -= mid / 2;
		ans.at(0) = mid;
		bool f = true;
		ll minpos = -1;
		for (int i = n - 1; i >= 1; i--) {
			if (ac.at(i) < 0) {
				minpos = i;
				break;
			}
			ans.at(i) = ac.at(i) * 2;
			ac.at(i - 1) -= ac.at(i);
			ac.at(i) = 0;
			if (ac.at(i - 1) < 0) {
				minpos = i - 1;
				break;
			}
		}
		if (minpos % 2 == 0)f = false;
		if (f) {
			if (ac.at(0) > 0)l = mid/2;
			else {
				r = mid/2;
				break;
			}
		}
		else r = mid/2;
	}
	for (int i = 0; i < n; i++) {
		if (i == 0)cout << ans.at(i);
		else cout << " " << ans.at(i);
	}
}

Measured memory_bytes: 3696
n=int(input())
lists=[[] for _ in range(n)]
for i in range(n):
    a=int(input())
    for j in range(a):
        x,y=map(int,input().split())
        lists[i].append([x,y])
ans=0
for k in range(2**n):
    subans=0
    flag=True
    string=format(k,"0%ib"%n)
    listss=["unknown" for i in range(n)]
    for i in range(n):
        if string[i]=="1":
            #正直者だとした場合の全探索
            subans+=1
            for some in lists[i]:
                if listss[some[0]-1]=="unknown":
                    listss[some[0]-1]=some[1]
                elif listss[some[0]-1]!="unknown":
                    if listss[some[0]-1]!=some[1]:
                        flag=False
                        break

    if flag:
        flags=True
        for i in range(n):
            if  listss[i]!="unknown" and listss[i]!=int(string[i]):
                flags=False
        if flags:
            ans=max(ans,subans)

print(ans)        

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

int main() {
    vector<pair<int, int> > hw;
    for (int i = 0; ; i++) {
        int h, w;
        scanf("%d%d", &h, &w);
        if (h == 0 && w == 0) {
            break;
        }
        pair<int, int> p(h, w);
        hw.push_back(p);
    }
    
    for (int i = 0; i < hw.size(); i++) {
        for (int j = 0; j < hw.at(i).first; j++) {
            for (int k = 0; k < hw.at(i).second; k++) {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
}


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

public class Main {

    static int rows;
    static int colomns;
    static int[][] matrix;

    static void table(){
        matrix[0][1] = 1;
        for(int i=1;i<=rows;i++){
            for(int j=1;j<=colomns;j++){

                if(matrix[i][j]==0) {
                    int a = matrix[i - 1][j];
                    int b = matrix[i][j - 1];

                    if(a<0){
                        a = 0;
                    }
                    if(b<0){
                        b = 0;
                    }

                    matrix[i][j] = (a+b)%1000000007;

                }
            }
        }
    }

    static void ans(){
        System.out.println(matrix[rows][colomns]);
    }

    public static void main(String[] args) throws IOException {

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

        String[] one = inp.readLine().split(" ");
        rows = Integer.parseInt(one[0]);
        colomns = Integer.parseInt(one[1]);

        matrix = new int[rows+1][colomns+1];

        for(int i=1;i<=rows;i++){
            String[] line = inp.readLine().split("");
            for(int j=1;j<=colomns;j++){
                if(line[j-1].equals("#")){
                    matrix[i][j]= -1;
                }
            }
        }

        table();
        ans();


    }
}


Measured memory_bytes: 63480
k_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

K = int(input())
print(k_list[K-1])

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#pragma warning( disable:4996 )
using namespace std;

#define GMAX 1400
int G[GMAX][GMAX];
int dp[GMAX][GMAX];

int getLargestSquare(int H, int W)
{
	int existClean = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			dp[i][j] = (G[i][j] + 1) % 2;
			existClean |= dp[i][j];
		}
	}
	if (H == 1 || W == 1) return existClean;
	int maxWidth = 0;
	for (int i = 1; i < H; i++) {
		for (int j = 1; j < W; j++) {
			if (G[i][j]) {
				dp[i][j] = 0;
			}
			else {
				dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1]))+1;
				maxWidth = max(maxWidth, dp[i][j]);
			}
		}
	}
	return maxWidth* maxWidth;
}

int main()
{
	int H, W;
	scanf("%d %d", &H, &W);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) scanf("%d", &G[i][j]);
		
	}
	printf("%d\n", getLargestSquare(H, W));
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  int a = 0;
  cin >> s;
  for (auto &c : s) {
    a += c - '0';
  }
  if (a % 9 == 0) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail {
template <typename T, std::size_t NDIMS>
struct vector_builder {
  using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
    if (!dims.empty()) dims.pop_back();
    return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
  }
};

template <typename T>
struct vector_builder<T, 1> {
  using type = std::vector<T>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    return type(dims.empty() ? 0 : dims.back(), v);
  }
};
}  // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T& v, SIZE_T... dims) {
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T& data, vector<int>& iter) {
  cout << data << " ";
}
template <typename T>
void dump(const vector<T>& data, vector<int>& iter) {
  for (auto elem : data) dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>>& data, vector<int>& iter) {
  for (auto elem : iter) {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++) {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T>& data, int dummy) {
  for (int i = 0; i < data.size(); i++) {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T& data) {  // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

int main() {
  cout << setprecision(10);
  LL a, b, c, d, e, f, g;
  cin >> a >> b >> c >> d >> e >> f >> g;

  LL ans = 2 * b;

  LL ijl = min({a, d, e});
  ans += 6 * ijl;
  a -= ijl;
  d -= ijl;
  e -= ijl;
  ans += a / 2 * 4;
  ans += d / 2 * 4;
  ans += e / 2 * 4;

  LL amari = 0;
  amari = (a % 2) + (d % 2) + (e % 2);

  if (amari > 1 && ijl > 0) {
    ans = ans - 6 + 4 * amari;
  }
  cout << ans / 2 << endl;

  return 0;
}


Measured memory_bytes: 256
import collections
N, K = map(int, input().split())
A = list(map(int, input().split()))
a = collections.Counter(A)
c = len(A)
#print(a.most_common(K))
S = a.most_common(K)
for i in range(K):
    try:
        c -= S[i][1]
    except IndexError:
        print(c)
        exit()
print(c)


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

    val dp = Array(n + 1) { Array(3) { 0L } }

    for (i in 0 until n) {
        for (j in 0..2) {
            for (k in 0..2) {
                if (j == k) {
                    continue
                }
                dp[i + 1][k] = Math.max(dp[i + 1][k], dp[i][j] + abc[i][k])
            }
        }
    }

    var ans = 0L
    for (i in 0..2) {
        ans = Math.max(ans, dp[n][i])
    }
    println(ans)
}

Measured memory_bytes: 95232
X, K, D = map(int, input().split())
X = abs(X)
if X >= K * D:
    print(abs(X - K * D))
    exit()

m = X % D
if m != 0:
    a = X // D
    if (K - a) % 2 == 0:
        print(m)
    else:
        print(D - m)
else:
    a = X // D
    if (K - a) % 2 == 0:
        print(0)
    else:
        print(D)


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

int main()
{
   int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int i;
    for (i=sy+1 ; i<=ty ; i++)
    {
        cout << "U";
    }
    for (i=sx+1 ; i<=tx ; i++)
    {
        cout << "R";
    }
    for (i=ty-1 ; i>=sy ; i--)
    {
        cout << "D";
    }
    for (i=tx-1 ; i>=sx ; i--)
    {
        cout << "L";
    }
    cout << "L";
    for (i=sy ; i<=ty ; i++)
    {
        cout << "U";
    }
    for (i=sx ; i<=tx ; i++)
    {
        cout << "R";
    }
    cout << "DR";
      
    for (i=ty ; i>=sy ; i--)
    {
        cout << "D";
    }
    for (i=tx ; i>=sx ; i--)
    {
        cout << "L";
    }
    cout << "U" ;
    return 0;
}

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

int main(){
  int a, b, c, d, e, k; cin >> a >> b >> c >> d >> e >> k;
  
  if(b-a>k){
  	cout << ":(" << endl;
  	return 0;
  }
  if(c-b>k){
  	cout << ":(" << endl;
  	return 0;
  }
  if(d-c>k){
  	cout << ":(" << endl;
  	return 0;
  }
  if(e-d>k){
  	cout << ":(" << endl;
  	return 0;
  }
  if(c-a>k){
  	cout << ":(" << endl;
  	return 0;
  }
  if(d-b>k){
  	cout << ":(" << endl;
  	return 0;
  }
  if(c-a>k){
  	cout << ":(" << endl;
  	return 0;
  }
  if(d-a>k){
  	cout << ":(" << endl;
  	return 0;
  }
  if(e-b>k){
  	cout << ":(" << endl;
  	return 0;
  }
  if(e-a>k){
  	cout << ":(" << endl;
  	return 0;
  }
  cout << "Yay!" << endl;
  
}


Measured memory_bytes: 256
import java.util.*;class Main{public static void main(String[]_){String s="";int h,l,a,f;for(Scanner S=new Scanner(System.in);(l=S.nextInt())+(h=S.nextInt())>0;s+=f<1?"NA\n\n":"\n"){for(f=0,a=l;a<=h;a++)if(a%4<1&&(a%100>0||a%400<1)){s+=a+"\n";f=1;}}System.out.println(s.trim());}}

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

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

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



int main() {
	int x, a, b;
	cin >> x >> a >> b;
	x -= a;
	while (x >= b)x -= b;
	print(x);





	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
 
 int main (){
     int W,H,x,y,r;
     cin >> W >> H >> x >> y >>r;
     if (x<0 || y<0){
          cout << "No" << endl;
     }
     else if(x+r<=W && y+r<=H){
         cout << "Yes" << endl;
     }else{
         cout << "No" << endl;
     }
 }


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define INF 10000000000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll,short> P;
typedef pair<int,short> P2;

int n;
vector<int> G[5005];
ll x[5005];
int u[5005],v[5005];
ll dp[5005][5005];
ll tmp[5005];
ll subsum[5005];
int child[5005];
ll sum;
ll min_v=0;
int tp=0;

ll labs(ll v){
	if(v<0LL)return -v;
	return v;
}

ll dfs(int v,int p){
	ll su=x[v];
	for(int i=0;i<G[v].size();i++){
		int nv=G[v][i];
		if(nv==p)continue;
		su+=dfs(G[v][i],v);
	}
	return subsum[v]=su;
}

int dfs1(int v,int p){
	int su=1;
	for(int i=0;i<G[v].size();i++){
		int nv=G[v][i];
		if(nv==p)continue;
		su+=dfs1(G[v][i],v);
	}
	return child[v]=su;
}

void dfs2(int v,int p){
	int siz=0;
	for(int i=0;i<G[v].size();i++){
		int nv=G[v][i];
		if(nv==p)continue;
		dfs2(G[v][i],v);
		for(int j=0;j<=n;j++){
			tmp[j]=INF;
		}
		for(int j=0;j<=siz;j++){
			for(int k=0;k<=min(tp,child[nv]);k++){
				ll nc=labs(subsum[nv]-child[nv]*min_v-k);
				tmp[j+k]=min(dp[v][j]+dp[nv][k]+nc,tmp[j+k]);
			}
		}
		for(int j=0;j<=n;j++){
			dp[v][j]=tmp[j];
		}
		siz+=child[nv];
	}
	for(int i=n;i>=1;i--){
		dp[v][i]=min(dp[v][i],dp[v][i-1]);
	}
}

int main(void){
	scanf("%d",&n);
	int S=n;
	int T=n+1;
	sum=0;
	for(int i=0;i<n;i++){
		scanf("%lld",&x[i]);
		sum+=x[i];
	}
	tp=(ll)sum%n;
	min_v=(ll)sum/n;
	for(int i=0;i<n-1;i++){
		scanf("%d%d",&u[i],&v[i]);
		u[i]--;
		v[i]--;
		G[u[i]].push_back(v[i]);
		G[v[i]].push_back(u[i]);
	}
	dfs(0,-1);
	dfs1(0,-1);
	dfs2(0,-1);
	printf("%lld\n",dp[0][sum%n]);
	return 0;
} 


Measured memory_bytes: 199744
import java.util.*;
import static java.lang.System.*;
import java.io.*;
import java.math.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();
		for(int i = 0; i < n; i++) {
			out.print(s[i]);
			out.print(t[i]);
		}
		

		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}

Measured memory_bytes: 22740
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();

    int fee = B;
    if (6 <= A && A <= 12) {
      fee = B/2;
    } else if (A <= 5) {
      fee = 0;
    }
    System.out.println(fee);
  }
}



Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
    int n;
    cin >> n;
    int ans=0;
    rep(i, n+1){
        if(0 < i && i < 10) ans++;
        else if (99 < i && i < 1000) ans++;
        else if (9999 < i && i < 100000) ans++;
    }
    cout << ans <<endl;
    return 0;
}

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

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

  if (a < b){
    cout << "a < b" << endl;

  }
  else if (a > b){

    cout << "a > b" << endl;
  }

  else {

    cout << "a == b" << endl;
  }
  return 0;

}

Measured memory_bytes: 1156
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[15],r[15],l[15],lcnt,rcnt,cnt;
bool flag;
bool solve(){
	for(int i=0;i<1024;++i){
		memset(l,0,sizeof(l));
		memset(r,0,sizeof(r));
		lcnt=rcnt=0;
		for(int cnt=0,j=i;cnt<10;cnt++,j>>=1){
			if(j&1)l[lcnt++]=a[cnt];
			else r[rcnt++]=a[cnt];
		}
		flag=true;
		for(int j=1;j<lcnt;j++){
			if(l[j]<l[j-1]){
				flag=false;
				break;
			}
		}
		if(flag){
			for(int j=1;j<rcnt;j++){
				if(r[j]<r[j-1]){
					flag=false;
					break;
				}
			}
		}
		if(flag)return true;//只要能找出就返回true 
	}
	return false;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		for(int i=0;i<10;i++)cin>>a[i];
		puts(solve()?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

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

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
class Edge{
public:
    int from,to,value;
    Edge(int a,int b,int c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};


int main(){
    string str;cin >> str;
    string s ="abcdefghijklmnopqrstuvwxyz";
    for(int a = 0;a<s.size();a++){
        if(find(str.begin(),str.end(),s.at(a))==str.end()){
            COUT(s.at(a));
            rt 0;
        }
    }
    COUT("None");
    rt 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();    
    if(a * b < c){
      System.out.println(a * b);
    }else{
      System.out.println(c);
    }
  }
}


Measured memory_bytes: 23764
<?php
fscanf(STDIN, '%d', $n);
$numbers = fgets(STDIN);
$exploded_numbers = explode(' ', trim($numbers));
$base_numbers = $exploded_numbers;
sort($exploded_numbers);

$count = 0;
foreach ($base_numbers as $key => $num) {
  if ($num != $exploded_numbers[$key]) {
    $count++;
  }
}
if ($count == 2 || $count == 0) {
  echo 'YES';
} else {
  echo 'NO';
}

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

int main() {
  int A,B;
  int A1,A2,A3,A4,A5;
  cin >> A >> B;
  int hold_A=A;
  int hold_B=B;  
  int count=0;
  
  for(int i =0;i<90000;i++){
  A1 = A /10000;
  A2 = A / 1000 % 10;
  A3 = A / 100 % 10;
  A4 = A / 10 % 10;
  A5 = A % 10;
    
    if(A >= hold_A){
      if(A1 == A5 && A2 == A4){
        count++;
      }
    }
    if(A == hold_B) break;
    A++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
-- http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_D

main = do
    l <- getLine
    let t = read l :: Int
    putStrLn $ (show $ hour t) ++ ":" ++ (show $ minute t) ++ ":" ++ (show $ second t)

hour :: Int -> Int
hour time = div time 3600

minute :: Int -> Int
minute time = div (mod time 3600) 60

second :: Int -> Int
second time = mod time 60



Measured memory_bytes: 3660
a,b,c,x,y=map(int,input().split())
ans1=a*x+b*y
ans2=2*c*max(x,y)
ans3=2*c*min(x,y)+a*(x-min(x,y))+b*(y-min(x,y))
print(min(ans1,ans2,ans3))

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

const int Nmax = 51;

int N, M;
int a[Nmax*Nmax], b[Nmax*Nmax];
int par[Nmax], depth[Nmax];

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

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

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

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

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

	int ans = 0;
	for (int i = 0; i < M; i++) {
		init(N);
		for (int m = 0; m < M; m++) {
			if (m != i) {
				unite(a[m], b[m]);
			}
		}

		for (int n = 0; n < N; n++) {
			if (find(0) != find(n)) {
				ans++;
				break;
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256