akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    //https://atcoder.jp/contests/dp/tasks/dp_a

   private static int[] dp = null;

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

        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }

        dp = new int[n + 1];
        Arrays.fill(dp, -1);

       /* int value = dfs(arr, n, 0);
        System.out.println(value);*/

        int val = solveTopDown(n - 1, arr);
        System.out.println(val);

    }

    private static int dfs( int[] arr, int n, int temp ) {

       /* if (dp[temp] != -1)
            return dp[temp];*/

        if (temp == n) //if no element in an array then
            return 0;

        if (temp == n - 1) //if no element in an array then
            return arr[n - 1];

        if (temp == n - 2) //if only element in array then difference of two will be the cost.
            return Math.abs(arr[temp] - arr[temp - 1]);

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

            if (i + 2 < n) {

                dp[i] = Math.min(Math.abs(arr[i] - arr[i + 1]) + dfs(arr, n, i + 1)
                        , Math.abs(arr[i] - arr[i + 2]) + dfs(arr, n, i + 2));
            }
        }

        return dp[n];
    }

    private static int solveTopDown( int i, int[] arr ) {
        if (dp[i] != -1) {
            return dp[i];
        }

        if (i == 0) { //if one element left
            dp[i] = 0;
            return dp[i];
        } else if (i == 1) { //if two left
            dp[i] = Math.abs(arr[i] - arr[i - 1]);
            return dp[i];
        }

        dp[i] = Math.min(Math.abs(arr[i] - arr[i - 1]) + solveTopDown(i - 1, arr)
                , Math.abs(arr[i] - arr[i - 2]) + solveTopDown(i - 2, arr));

        return dp[i];
    }
}

Measured memory_bytes: 64932
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Int32;
using static System.Math;

class Program
{

    static void Main(string[] args)
    {
        label:
        var sp = ReadLine().Split();
        int n = Parse(sp[0]);
        int m = Parse(sp[1]);
        int x, y, z;
        if (Can(n, m, out x, out y, out z))
        {
            WriteLine($"{x} {y} {z}");
        }
        else
        {
            WriteLine("-1 -1 -1");
        }
        //goto label;
    }
    static bool Can(int n, int m, out int x, out int y, out int z)
    {
        x = y = 0;
        z = (m / 1000) % 5;
        while (true)
        {
            int xPlusY = n - z;
            if (xPlusY < 0) return false;
            // 10000x+5000y+1000z=m
            // 10000x+5000y=m-1000z
            // 2x+y=(m-1000z)/5000
            int x2PlusY = (m - 1000 * z) / 5000;
            x = x2PlusY - xPlusY;
            y = xPlusY - x;
            if (0 <= x && 0 <= y) return true;
            z += 5;
            if (2000 < z) return false;
        }
    }
}


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

int main() {
    int x, n;
    cin >> x >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];

    int small;
    int large;
    for(int i = x; ; --i) {
        if(find(p.begin(), p.end(), i) == p.end()) {
            small = i;
            break;
        }    
    }

    for(int i = x; ; ++i) {
        if(find(p.begin(), p.end(), i) == p.end()) {
            large = i;
            break;
        }    
    }

    int ans;
    if(large - x < x - small) ans = large;
    else ans = small;

    cout << ans << endl;
    return 0;


}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <set>
using namespace std;
int main(){
	int q,a,b;
	string s;
	cin>>q;
	set<string>m;
	for(;q--;){
		cin>>a;
		if(a==0)cin>>s,m.insert(s),cout<<m.size()<<endl;
		if(a==1)cin>>s,cout<<m.count(s)<<endl;
		if(a==2)cin>>s,m.erase(s);
	}
}



Measured memory_bytes: 21808
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
typedef pair<int, int> PII;
typedef long long ll;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

string s;
int n, ans;

int main() {

	cin >> n >> s;

	rep(i, n - 2){
		if (s[i] == 'A'){
			if (s[i + 1] == 'B'){
				if (s[i + 2] == 'C'){
					ans++;
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
unittest
{
	assert( [ "3 3 10", "1 2 20", "2 3 30", "1 3 45" ].parse.expand.solve == 35 );
	assert( [ "2 2 10", "1 2 100", "2 2 100" ].parse.expand.solve == -1 );
	assert( [ "4 5 10", "1 2 1", "1 4 1", "3 4 1", "2 2 100", "3 3 100" ].parse.expand.solve == 0 );
}



import std.algorithm;
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 nmp = input.front.split.to!( long[] );
	auto abcs = new long[ 3 ][ nmp[ 1 ] ];
	foreach( ref abc; abcs )
	{
		input.popFront;
		abc = input.front.split.to!( long[] );
		abc[ 0 .. 2 ] -= 1;
	}
	return tuple( nmp[ 0 ], nmp[ 2 ], abcs );
}

auto solve( long n, long p, long[ 3 ][] abcs )
{
	// 時間経過による支払いを経路のコストに含める
	// ついでに獲得コイン数をマイナスにして普通の最短経路問題にする
	foreach( ref abc; abcs )
	{
		abc[ 2 ] = p - abc[ 2 ];
	}
	
	// 最大獲得コイン数を計算
	auto cs = bellmanford( n, abcs, 0 );
	if( cs[ $ - 1 ] == long.min ) return -1L;							// 無限ループで最大値なし
	else                          return max( -cs[ $ - 1 ], 0L );		// 支払いより稼いでいれば獲得コイン数、そうでなければ0
}

// 正負の重み付きグラフの始点指定最短経路探索（ベルマンフォード法）
auto bellmanford( long n, long[ 3 ][] es, long s )
{
	auto ds = new long[ n ];
	ds[] = long.max;
	ds[ s ] = 0;
	
	foreach( c; 0L .. n * 2 )
	{
		auto r = false;
		foreach( i, e; es )
		{
			auto td = ( ds[ e[ 0 ] ] == long.min ) ? long.min : ds[ e[ 0 ] ] + e[ 2 ];
			if( ds[ e[ 0 ] ] == long.max || ds[ e[ 1 ] ] <= td ) continue;
			ds[ e[ 1 ] ] = ( c < n ) ? td : long.min;		// 頂点数以上ループしても更新がある場合、負のループが存在するのでminで塗りつぶす
			r = true;
		}
		if( !r ) break;		// 更新がない場合、最短経路に収束済みなので打ち切り
	}
	return ds;
}


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

int main(void){
  int N, M;
  cin >> N >> M;
  vector<int> L, R;
  int maxL = 0;
  int minR = INT_MAX;
  for(int i=0; i<M; i++) {
    int l, r;
    cin >> l  >> r;
    L.push_back(l);
    R.push_back(r);
    if(l > maxL) { maxL = l; };
    if(r < minR) { minR = r; };
  }
  int ret = minR - maxL + 1;
  if(ret > 0) {
    cout << ret << endl;    
  } else {
    cout << 0 << endl;
  }
}

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

int main(){
  int K,N;
  cin >> K >> N;
  vector<int> x(N);
  
  for(int i=0;i<N;i++)
    cin >> x.at(i);
  
  int y=K-x.at(N-1);
  x.at(0)+=y;
  
  reverse(x.begin(),x.end());
  
  for(int i=0;i<N-1;i++){
    x.at(i)-=x.at(i+1);
  }
  
  sort(x.begin(),x.end());
  
  cout << K-x.at(N-1) << endl;
}

Measured memory_bytes: 1024
import random
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def score(tt):
    ans=0
    for i,t in enumerate(tt):
        t-=1
        ans += ss[i][t]
        p = i - last[t]
        ans -= p * (p + 1) // 2 * cc[t]
        last[t] = i + 1
    for t in range(26):
        p = d - last[t]
        ans -= p * (p + 1) // 2 * cc[t]
    return ans

inf=10**16
d = II()
cc = LI()
ss = LLI(d)
ans = 0
last = [0] * 26
tt=list(range(1,27))*(d//26+1)
tt=tt[:d]
for _ in range(20000):
    i=random.randrange(d)
    mx=-inf
    best=1
    for j in range(1,27):
        tt[i]=j
        cur=score(tt)
        if cur>mx:
            mx=cur
            best=j
    tt[i]=best
#print(score(tt))
print(*tt,sep="\n")


Measured memory_bytes: 78456
S=input()

l=[]
i=0
if len(S)%2==0:
    for n in range(len(S)//2):
        l.append(S[n])
    for n in range(len(S)//2,len(S)):
        a=l.pop()
        if S[n]!=a:
            i+=1
    print(i)

else:
    for n in range(len(S)//2):
        l.append(S[n])
    for n in range(len(S)//2+1,len(S)):
        a=l.pop()
        if S[n]!=a:
            i+=1
    print(i)


Measured memory_bytes: 3064
lr = input().split()
l = int(lr[0])
r = int(lr[1])
 
mini = 2018
 
for i in range(l, r+1):
  for j in range(i+1, r+1):
    mini = min(mini, (i*j)%2019)
 
    if mini==0:
      break
  if mini==0:
    break
print(mini)

Measured memory_bytes: 3060
sl = list(input())
dl = []

n = len(sl)
i = 0
while i < n:

    if i < n-1 and sl[i] == "B" and sl[i+1] == "C":
        dl.append("D")
        i += 2
    else:
        dl.append(sl[i])
        i += 1

ans = 0
c = 0
for d in dl:
    if d == "A":
        c += 1
    elif d == "D":
        ans += c
    else:
        c = 0


print(ans)



Measured memory_bytes: 61808
# A = [list(map(int, input().split())) for _ in range(3)]
# H = int(input())
# B = [int(input()) for _ in range(n)]
# A = list(map(int, input().split()))
# a, b = map(int, input().split())
S = input()
if S[2] == S[3] and S[4] == S[5]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
# coding: utf-8
# Your code here!

n = int(input())

a = input()
b = input()
c = input()

ans = 0

for i in range(n):
    x = 0
    x += a[i]!=b[i]
    x += b[i]!=c[i]
    x += c[i]!=a[i]
    if x==2:
        ans+=1
    if x==3:
        ans+=2
        
print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int A,B;
	cin>>A>>B;
	if (A==1 || B==1){
		if (A==B){
			cout<<"Draw"<<endl;
		}else if (A<B){
			cout<<"Alice"<<endl;
		}else{
			cout<<"Bob"<<endl;
		}
		return 0;
	}
	if (A==B){
		cout<<"Draw"<<endl;
	}else if (A>B){
		cout<<"Alice"<<endl;
	}else{
		cout<<"Bob"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var N = Sarray()[0];
            var Ai = Sarray();
            var min = long.MaxValue;
            for(var i=-100;i<=100;++i)
            {
                var sum = 0L;
                foreach(var a in Ai)
                    sum += (a - i) * (a - i);
                min = Min(min, sum);
            }
            WriteLine(min);
        }
    }
}

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

int isPrime(int x) {
  if (x == 2) return true;
  if (x < 2 || x % 2 == 0) return false;

  int i = 3;
  while (i <= sqrt(x)) {
    if (x % i == 0) return false;
    i = i + 2;
  }

  return true;
}

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

  vector<int> vec(N);

  int ans = 0;

  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    if (isPrime(vec.at(i))) ans++;
  }

  cout << ans << endl;
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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; }
const int INF = 1e18;

signed main(){
    int n, m; cin >> n >> m;
    vector<pair<int,int>> vec(m);
    REP(i,m){
        int a, b; cin >> a >> b; a--; b--;
        vec[i] = {a,b};
    }
    sort(all(vec));
    int left,right;
    int ans = 1;
    REP(i,m){
        if(i == 0){
            left = vec[i].first;
            right = vec[i].second;
        }
        else{
            if(vec[i].second <= left or vec[i].first >=right){
                ans++;
                chmin(left,vec[i].first);
                chmax(right,vec[i].second);
            }
            else{
                chmax(left,vec[i].first);
                chmin(right,vec[i].second);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//split??????????????§????????????????§£????????£??\
		String[] lines = sc.nextLine().split(" ");
		int[] nums ={ Integer.parseInt(lines[0]), Integer.parseInt(lines[1]), Integer.parseInt(lines[2]) };
		for(int i = 0; i < nums.length - 1;i++) {
			for(int j = 0; j < nums.length - 1; j++){
				if(nums[j] > nums[j + 1]) {
					int x = nums[j];
					nums[j] = nums[j + 1];
					nums[j + 1] = x;
				}

			}
		}

		//???????????¨??????
		System.out.println(nums[0] + " " + nums[1] + " " + nums[2]);

	}
}

Measured memory_bytes: 26256
#include <stdio.h>
#define N 101
#define W 0
#define Gl 1
#define B 2
void DFS_V(int);
int V;
int time;
int color[N];
int G[N][N];
int d[N];
int f[N];



 int main(){
  int i;
  int j;
  int k;
  int l;
  int u;
  int A[N];


  scanf("%d",&V);
  for(i=1;i <= V;i++) {
    for(j=1;j <= V;j++){
      G[i][j] = W;
    }
  }
   
  for(i=1;i <= V;i++){
    scanf("%d%d",&k,&l);
    for(j=1;j <= l;j++){
      scanf("%d",&A[j]);
      G[k][A[j]] = Gl;
    }
  }
   

  for(u=1;u <= V;u++){
    color[u] = W;
    time = 0;
  }
  for(u=1;u <= V;u++){
    if(color[u] == W){
      DFS_V(u);
    }
  }
  for(i=1;i<=V;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
  return 0;
}
 
 
void DFS_V(int u){
  int v;
  color[u] = Gl; // White vertex u has just been discovered
  d[u] = ++time;
  for(v=1;v<= V ;v++){ // Explore edge (u,v)
    if(color[v] == W && G[u][v] == Gl){
      DFS_V(v);
    }
  }
  color[u] = B; // Blacken u; it is finished
  f[u] = ++time;
   
}

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

int main(){
  int N;
  int AC = 0;
  int WA = 0;
  int TLE = 0;
  int RE = 0;
  cin >> N;
  vector<string> S(N);
  for(int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  for(int i = 0; i < N; i++) {
    if (S.at(i) == "AC") {
      AC++;
    }
    else if (S.at(i) == "WA") {
      WA++;
    }
    else if (S.at(i) == "TLE") {
      TLE++;
    }
    else if (S.at(i) == "RE") {
      RE++;
    }
  }
  cout << "AC x " << AC << endl;
  cout << "WA x " << WA << endl;
  cout << "TLE x " << TLE << endl;
  cout << "RE x " << RE << endl;
}

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

int main() {
  int N,A;
  cin >> N >> A;
  if(N <= A){
    cout << "Yes" << endl;
  }
  else{
    if((N%500) <= A){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
}


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


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

    int n;
    while(cin>>n){
        if(!n) break;
        string s[n];
        for(int i=0;i<n;i++){
            cin>>s[i];
        }
        int ans=0;
        int haiku[5] = {5,7,5,7,7};
        for(int i=0;i<n;i++){
            bool pos=true;
            int j=i;
            int cnt=0,now=0;
            while(pos && j<n){
                cnt+=s[j].size();
                if(cnt>haiku[now]){
                    pos=false;
                }
                if(cnt==haiku[now]){
                    cnt=0;
                    now++;
                }
                if(now==5) break;
                j++;
            }
            if(pos){
                cout<<i+1<<endl;
                break;
            }
        }
    }
    
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1e9 + 7;

int main() {
    ll h;
    cin >> h;
    int cnt = 0;
    while (h > 0) {
        cnt++;
        h /= 2;
    }
    ll ans = 1;
    for (int i = 0; i < cnt; i++) {
        ans *= 2;
    }
    cout << --ans << endl;
    return 0;
}

Measured memory_bytes: 3632
# 初期入力
import sys
from collections import deque
#input = sys.stdin.readline  #文字列では使わない
H,W = map(int, input().split())
S_h,S_w = map(int, input().split()) #スタート
G_h,G_w = map(int, input().split()) #ゴール

#迷路
mp =[["#"]*(W +4) for i in range(H +4)] #上下左右に２個分余分に壁を作る
for i in range(2,H+2):
    mp[i][2:-2] =input().strip() #迷路読み込み
    
S_h +=1 #壁を余分に作った分、スタートとゴールをずらす
S_w +=1
G_h +=1
G_w +=1
used =[[float('inf')]*(W +4) for i in range(H +4)] #既に通ったところを保存
used[S_h][S_w] =0
wap=[-2,-1,0,1,2] #ワープ移動できる縦横の範囲


dq =deque()
dq.append((0,S_h,S_w)) #キューには(コスト、x座標、y座標)を追加していく
arrive=False #ゴールに到着すればTrueに変更

while dq:
    k,i,j =dq.popleft()
    if k >used[i][j]: #既に通ったかどうか
        continue
    if i ==G_h and j ==G_w: #ゴール判定
        arrive =True
        break
    for di in wap:
        for dj in wap:
            if di ==0 and dj ==0: #その場から移動しない時
                continue
            ni,nj =i +di ,j +dj #移動後の座標(ni,nj)
            if mp[ni][nj] =="#": #移動先が壁の中
                continue
            if k <used[ni][nj]:
                if abs(di) +abs(dj) ==1: #歩行圏内(コスト:0)
                    nk =k
                    used[ni][nj] =nk
                    dq.appendleft((nk,ni,nj))
                else:                   #歩行圏外(コスト:１)
                    nk =k+1
                    used[ni][nj] =nk
                    dq.append((nk,ni,nj))
if arrive:
    ans =used[G_h][G_w]
else:
    ans =-1
print(ans)

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

int main(){
 int W,H,x,y,r;
 cin >> W >> H >> x >> y >> r;
 
 if(y+r<=H && x+r<=W && x-r>=0 && y-r>=0){
  cout << "Yes" << endl;
 }
 else{
  cout << "No" << endl;
 }

}


Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cstdio>
using namespace std;

int main() {
	int num[3];
	cin >> num[0] >> num[1] >> num[2];
	sort(num,num+3);
	if(num[0] + num[1] == num[2])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793
const int INF = 100000000;
int dx[] = {0,1,-1,0,1,-1,1,-1};
int dy[] = {1,0,0,-1,1,-1,-1,1};

int main(){
    int n, maxp = 0, sum = 0;
    cin >> n;
    while(n--){
        int p;
        cin >> p;
        maxp = max(maxp, p);
        sum += p;
    }
    cout << sum - maxp / 2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
long long gcd(long long a, long long b) { return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b) { return a/gcd(a,b)*b;}

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

int main() {
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  s += '0';
  int keta = s.size();
  int dp[keta + 1][2];
  rep (i, keta + 1) {
    rep (j, 2) {
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;

  rep (i, keta) {
    int x = s[i] - '0';
    int ni = i + 1;
    rep (j, 2) {
      int nj = 0;
      int a = x + j;
      dp[ni][nj] = min(dp[ni][nj], dp[i][j] + a);
      nj = 1;
      a = 10 - x - j;
      dp[ni][nj] = min(dp[ni][nj], dp[i][j] + a);
    }
  }

  // rep (i, keta + 1) {
  //   rep (j, 2) {
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  cout << dp[keta][0] << endl;
  return 0;
}


Measured memory_bytes: 9220
import sys
n = 10001
l = [0]*n
l[2] = 1
for i in xrange(3,n): l[i] = (i-1)+l[i-1]
for i in xrange(1,n): l[i] += i+1
for s in sys.stdin:
    d = int(s)
    print l[d]

Measured memory_bytes: 4512
<?php 
	$n = str_split(trim(fgets(STDIN)));
	$ans = "Yes";
	if(($n[0]==$n[1] && $n[2]==$n[1]) || ($n[2]==$n[1] && $n[2]==$n[3])){
		$ans = "Yes";
    }else{
		$ans = "No";
    }
echo $ans
?>

Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(int, x);

  while (1) {
    bool ok = true;
    for (int i = 2; i < x; ++i) {
      if (x % i == 0) ok = false;
    }
    if (ok) {
      cout << x << endl;
      return 0;
    }
    x++;
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
template <typename T>
inline T  read()
{
    char c=getchar();
    T x=0,f=1;
    while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
    while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return x*f;
}
template <typename T>
inline void write(T x) 
{
    if(x < 0) x = (~x) + 1, putchar('-');
    if(x / 10) write(x / 10);
    putchar(x % 10 | 48);
}
const int INF = 0x3f3f3f3f;
int main()
{
    ll n = read<ll>(), a = read<ll>(), b = read<ll>();
    if(a == 0)
    {
        cout<<0<<endl;
        return 0;
    }
    ll x = n/(a+b);
    ll y = n%(a+b);
    ll ans = min(y,a);
    ans += x*a;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n,l=map(int,input().split())
a=list(map(int,input().split()))
if a[0]+a[1]>=l:
  print("Possible")
  for i in range(n-1,0,-1):print(i)
  exit()
if a[-2]+a[-1]>=l:
  print("Possible")
  for i in range(1,n):print(i)
  exit()
ans=-1
for i in range(1,n):
  if a[i-1]+a[i]>=l:
    ans=i
    break
if ans==-1:print("Impossible")
else:
  print("Possible")
  for i in range(1,ans):print(i)
  for i in range(n-1,ans,-1):print(i)
  print(ans)


Measured memory_bytes: 14620
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int h, w, k;
int cnt, ans;

int main() {

    scanf("%d %d %d", &h, &w, &k);
    vector<vector<char>> map(h, vector<char>(w, 0));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            scanf(" %c", &map[i][j]);
        }
    }
    for (int mask_h = 0; mask_h < (1 << h); ++mask_h) {
        for (int mask_w = 0; mask_w < (1 << w); ++mask_w) {
            cnt = 0;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; ++j) {
                    if (((mask_h >> i) & 1) == 0 && ((mask_w >> j) & 1) == 0 && map[i][j] == '#') {
                        cnt++;
                    }
                }
            }
            if (cnt == k) {
                ans++;
            }
        }
    }

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


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

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define repd(i, a, b) for (int i=(a);i<(b);i++)
#define rep(i, n) repd(i,0,n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMinimum(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMaximum(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template<typename T>
T output(T answer) {
    cout << answer << endl;
    return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {

    int A, P;
    cin >> A >> P;


    P = P + A * 3;

    int ans;
    ans = P / 2;

    cout << ans << endl;
}

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

int main() {
  int64_t N;
  int j=0;
  int result=2;
  vector<int64_t> a(100000);
  cin >> N;
  
  if (N == 2){
    cout << 1;
    exit(0);
  }
  
  for (int64_t i=2 ; i*i <= N ; i ++){
    if (N % i == 0){
      a.at(j) = i;
      j++;
    }
  }
  
  for (int64_t i = 2; i*i <= (N-1) ; i++){
    if ( i*i == (N-1)){
      result ++;
    }
    else if ( (N-1) % i == 0){
    result += 2;
    }
  }

  for (int i=0 ; i < j ; i ++){
    int64_t Nt = N;
    
    while( Nt % a.at(i) == 0){
      Nt /= a.at(i);
         if ( Nt % a.at(i) == 1){
      result++;
    }
    }
    
 
  }
  cout << result;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define rrep(i,n) for(int i=(n);i>=0;--i)
#define ssort(n) sort((n).begin(),(n).end())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;

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

Measured memory_bytes: 3636
#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;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
        constexpr int dy[] = {-1, 0, 1, 0}, dx[] = {0, -1, 0, 1};

        int h, w;
        cin >> h >> w;
        
        auto grid = make_v(h, w, '0');
        REP(i, h)REP(j, w) {
                cin >> grid[i][j];
        }

        auto isWall = [&](int i, int j) {
                return grid[i][j] == '#';
        };

        auto inGrid = [&](int i, int j) {
                return 0 <= i && i < h && 0 <= j && j < w;
        };

        int ans = -1;

        REP(i, h)REP(j, w)REP(k, h)REP(l, w) {
                if (isWall(i, j) || isWall(k, l)) {
                        continue;
                }

                auto distance = make_v(h, w, -1); 
                queue<pair<int, int>> q;

                distance[i][j] = 0;
                q.push({i, j});

                while (!q.empty()) {
                        auto now = q.front();
                        q.pop();

                        const int y = now.first, x = now.second;
                
                        if (y == k && x == l) {
                                ans = max(ans, distance[y][x]);
                        }

                        REP(m, 4) {
                                const int ny = y + dy[m], nx = x + dx[m];
                                if (inGrid(ny, nx) && !isWall(ny, nx) && distance[ny][nx] == -1) {
                                        distance[ny][nx] = distance[y][x] + 1;
                                        q.push({ny, nx});
                                }
                        }
                }
        }

        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split())) ##上段
B = list(map(int,input().split())) ##下段

dp = [[] for i in range(N)]
dp[0] = A[0] + B[0]
UpSum = A[0]
for i in range(1,N):
    UpSum += A[i] 
    dp[i] = max(dp[i-1],UpSum) + B[i]
print(dp[-1])

Measured memory_bytes: 9144
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

int main() {
  ll A, B;
  cin >> A >> B;
  if((A + B) % 2) cout << "IMPOSSIBLE" << endl;
  else cout << (A + B) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long lint;
using namespace std;
#define INF 1e18

int A,B,Q;



int main()
{
	cin >> A >> B;

	if (B % A == 0) {
		cout << A+B << endl;
	}
		else cout << B-A << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
  int a;
  int b;
  cin>>a>>b;
  if(a>b){
    REP(i,a){
      cout<<b;
    }
    cout<<endl;
  }
  else{
    REP(i,b){
      cout<<a;
    }
    cout<<endl;
  }
}

Measured memory_bytes: 888
#include<iostream>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#define pb push_back
#define ff first
#define ss second
using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    string p="";
    for(int i=0;i<k-1;i++){
        p+=s[i];
    }
    int r = s[k-1]-65;
    char b = r+97;
    p+=b;
    for(int i=k;i<n;i++){
        p+= s[i];
    }
    cout<<p<<endl;
}

Measured memory_bytes: 256
class PriorityQueue
  attr_accessor(:node)
  
  def initialize(src = [])
    @node = []
    src.each do |e|
      push(e)
    end
  end

  def push(x)
    @node << x
    bottom_up
  end

  def pop
    res = @node.first
    top_down
    return res
  end
  
  def bottom_up
    i = @node.size - 1
    v = @node[i]
    while i > 0
      parent = (i - 1) >> 1
      break if @node[parent] >= v
      
      @node[parent], @node[i] = @node[i], @node[parent]
      i = parent
    end
    
    @node[i] = v
  end

  def top_down
    i = 0
    tmp = @node.pop
    while (i << 1) + 1 < @node.size
      lhs = (i << 1) + 1
      rhs = (i << 1) + 2
      m = lhs
      
      if rhs < @node.size && @node[lhs] < @node[rhs]
        m = rhs
      end
      
      break if @node[m] <= tmp
      @node[i] = @node[m]
      i = m
    end
    
    @node[i] = tmp unless @node.empty?
  end
end

n, m = $stdin.readline.chomp.split.map(&:to_i)
t = Array.new(m) { Array.new }
n.times do
  a, b = $stdin.readline.chomp.split.map(&:to_i)
  next if a > m

  t[a - 1] << b
end

res = 0
pq = PriorityQueue.new
m.times do |i|
  t[i].each do |b|
    pq.push(b)
  end

  if !pq.node.empty?
    res += pq.pop
  end
end
puts res

Measured memory_bytes: 24836
import java.util.*;
import java.lang.reflect.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a  = sc.nextInt();
        int b  = sc.nextInt();
        int ans = Math.max(a - b,Math.max(a+b,a*b));
        System.out.println(ans);
    }
}

Measured memory_bytes: 20820
n = int(input())
s1 = list(input())
s2 = list(input())
if s1[0] == s2[0]:
    ans = 3
    i = 1
    flg = "x"
else:
    ans = 6
    i = 2
    flg = "y"
while i < n:
    if s1[i] == s2[i]:
        if flg == "x":
            ans *= 2
        else:
            flg = "x"
        i += 1
    else:
        if flg == "x":
            ans *= 2
            flg = "y"
        else:
            ans *= 3
        i += 2
    ans %= 10 ** 9 + 7
print(ans)

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

using namespace std;



int main(){
    int n; cin >> n;
    char S[n];
    for(int i = 0 ; i < n ; i ++) cin >> S[i];
    
    sort(S , S + n);
    
    int cnt = 1;
    for(int i = 0 ; i < n - 1 ; i ++){
        if(S[i + 1] != S[i]) cnt ++;
    }
    
    if(cnt == 3) cout << "Three" << endl;
    else if(cnt == 4) cout << "Four" << endl;
    
    return 0;
}


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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    vector<int> a(3);

    cin >> a[0] >> a[1] >> a[2];

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

    cout << a[0]+a[1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
#define INF 1000000001

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n;cin>>n;
  int mx=0;
  int mn=1000;
  REP(i,n){
    int a;cin>>a;
    mx=max(a,mx);
    mn=min(a,mn);
  }
  P(mx-mn);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    char x,y; cin>>x>>y;
    if(x<y) cout<<'<'<<endl;
    else if(x==y) cout<<'='<<endl;
    else cout<<'>'<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<numeric>
#include<cmath>
#include<cstdlib>
#include<string>
#include <limits>
using namespace std;


int main(){
  string S;

  cin>>S;
  if(S =="A")
    cout<<"T"<<endl;
  else if(S =="T")
    cout<<"A"<<endl;
  else if(S == "C")
    cout<<"G"<<endl;
  else if(S == "G")
    cout<<"C"<<endl;
}

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


int main (void) {

  int N; std::cin >> N;

  std::vector<int> A(N);
  for(int i=0; i<N; i++){
    std::cin >> A[i];
  }
 
  int ans = 0;
  while(1){
    bool flag = false;
    for(int i=0; i<N; i++){
      if ( A[i] % 2 == 1 ) flag = true;
      A[i] = A[i] / 2;
    }
    if ( flag ) break;
    else ans++;
  }

  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	ll x, y;
	cin >> x >> y;
	cout << (abs(x - y) <= 1 ? "Brown" : "Alice") << endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<cstdlib> 
#include<string>
#include<math.h>
#include<bitset>
#include<algorithm>
#include<vector>
#include<set>
#include<stack>
#include<queue>
using namespace std;
//typedef unsigned long long ull;


int main(){

	static unsigned long long n,a[100000],b[100000];

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

	unsigned long long ans=0;

	for(int i=n-1;i>=0;i--){
		ans+=(b[i]-(a[i]+ans%b[i])%b[i])%b[i];
		//cout << ans << endl;
	}

	cout << ans<< endl;

	//while(1);

}


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

int main()
{
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int ans = 0;
    for (int c = 0; c <= max(X, Y); ++c)
    {
        int price = 2 * c * C;
        if (X - c > 0)
        {
            price += (X - c) * A;
        }
        if (Y - c > 0)
        {
            price += (Y - c) * B;
        }
        if (ans == 0)
        {
            ans = price;
        }
        else
        {
            ans = min(price, ans);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
from collections import defaultdict, deque, Counter


def bfs(start):
    queue = deque([start])
    dist = [-1] * n
    dist[start] = 0
    while queue:
        v = queue.popleft()
        for nv in graph[v]:
            if dist[nv] != -1:
                continue
            queue.append(nv)
            dist[nv] = dist[v] + 1
    return dist


n, x, y = map(int, input().split())
# 0-indexed nodes
x -= 1
y -= 1

graph = defaultdict(set)
for i in range(n - 1):
    graph[i].add(i + 1)
    graph[i + 1].add(i)
graph[x].add(y)
graph[y].add(x)

dic = defaultdict(int)
for i in range(n):
    for k, v in Counter(bfs(i)).items():
        dic[k] += v

[print(dic[i] // 2) for i in range(1, n)]


Measured memory_bytes: 64604
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9 +7;
const ll inf=0x3f3f3f3f;
vector<int> son[5050];
int n,root;
ll ans;
int size[5050],deep[5050];
ll dis[5050],minn;
ll jc[5050],jc_ny[5050];
ll f[5050][5050];
ll Power(ll x,ll k)
{
	ll sss=1;
	while (k)
	{
		if (k%2) sss=sss*x%mod;
		x=x*x%mod;
		k/=2;
	}
	return sss;
}
ll ny(ll x){return Power(x,mod-2);}
ll C(int x,int y)
{
	if (y>x || y<0) return 0;
	if (y==x || y==0) return 1;
	ll sss=jc[x];
	sss=sss *jc_ny[x-y]%mod *jc_ny[y]%mod;
	return sss;
}
void init()
{
	jc[0]=1; jc_ny[0]=1;
	for (int i=1;i<=n;++i) jc[i]=jc[i-1]*i%mod,jc_ny[i]=ny(jc[i]);
}
void dfs(int x,int fa)
{
	deep[x]=deep[fa]+1;
	size[x]=1;
	int len=son[x].size();
	for (int i=0;i<len;++i)
	{
		int y=son[x][i];
		if (y==fa) continue;
		dfs(y,x);
		size[x]+=size[y];
	}
}
void get_dis(int x,int fa)
{
	int len=son[x].size();
	for (int i=0;i<len;++i)
	{
		int y=son[x][i];
		if (y==fa) continue;
		dis[y]=dis[x] -size[y] +(n-size[y]);
		get_dis(y,x);
	}
}
int main()
{
//	freopen("F.in","r",stdin);
//	freopen("F.out","w",stdout);

	scanf("%d",&n);
	init();
//	printf("%lld %lld\n",jc[3],jc_ny[3]);
//	printf("%lld\n",C(5,3));
	int x,y;
	for (int i=1;i<n;++i) 
	{
		scanf("%d%d",&x,&y);
		son[x].push_back(y);
		son[y].push_back(x);
	}
	deep[0]=-1;
	dfs(1,0);
	for (int i=1;i<=n;++i) dis[1]+=deep[i];
	get_dis(1,0);
//	for (int i=1;i<=n;++i) printf("%d ",size[i]);
//	printf("\n");
//	for (int i=1;i<=n;++i) printf("%lld ",dis[i]);
//	printf("\n");
	minn=inf;
	for (int i=1;i<=n;++i) minn=min(minn,dis[i]);
	for (int i=1;i<=n;++i) if (dis[i]==minn)
	{
		if (!root) root=i;
		else
		{
			printf("%lld\n",jc[n/2]*jc[n/2]%mod);
			return 0;
		}
	}
//	printf("root:%d\n",root);

	dfs(root,0);
	f[0][0]=1;
	int len=son[root].size(),sum=0;
	for (int i=1;i<=len;++i)
	{
		int y=son[root][i-1];
//		printf("%d : %d\n",y,size[y]);
		for (int j=0;j<=sum;++j) for (int k=0;k<=size[y];++k)
			(f[i][j+k]+= f[i-1][j]*C(size[y],k) %mod *C(size[y],k) %mod *jc[k]%mod )%=mod;
		
		sum+=size[y];
	}
	for (int i=0;i<=n;++i)
	{
		ll sss=f[len][i]*jc[n-i]%mod;
		if (i%2==0) ans+=sss;
		else ans-=sss;
	}
	printf("%lld\n",(ans%mod +mod)%mod);
	return 0;
}

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

int main(){
  	// ask user for a number
  	int N;
  	cin >> N;
  	string baha = "No";
  	
  	int i, j, temp;
  	for(i=1; i<=9; i++){
      	for(j=1; j<=9; j++){
        	temp = i*j;
   
  		if (N==temp){
          	baha = "Yes";
      	}
    }
    }
  	cout << baha;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 10000000000000000; //10^16
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    int K;
    string S;
    cin >> K >> S;
    if(S.size() <= K){
        cout << S << endl;
    }
    else{
        for(int i = 0; i < K; i++){
            cout << S.at(i);
        }
        cout << "..." << endl;
    }
}

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

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(x=from;x<to;x++)

using namespace std;


int main(void){

int dx[]={0,0,0,1,-1,1,1,-1,-1,0,0,2,-2};
int dy[]={0,1,-1,0,0,1,-1,1,-1,2,-2,0,0};
	int sz[4] ={0,5,9,13};
int mas[12][12]={0};
int x,y,s;
char zz;
	
	while(cin >> x >> zz >> y >>zz >> s ){
		rep(i,sz[s]){
			int xx=x+dx[i]; int yy=y+dy[i];
			if(xx >=0 && xx <=9 && yy >=0 && yy<=9) mas[xx][yy]++;
		}
	}
	int wcnt =0, mx =-999;
	rep(i,10) rep(j,10){
		if(mas[i][j]==0) wcnt++;
		mx = max(mx,mas[i][j]);
	}
	cout << wcnt << endl << mx << endl;;
	return 0;
}

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

bool cmp(int a,int b)
{
	return (a>b);
}

int main()
{
	int tab[110];
	int n;
	cin>>n;
	int sum=0;
	for (int i=1;i<=n;i++)
	 {
	 	cin>>tab[i];
	 	sum+=tab[i];
	 }
	sort(tab+1,tab+n+1,cmp);
	int a=0;
	for (int i=1;i<=n;i+=2)
	{
		a+=tab[i];
	}
	int sisa=sum-a;
	cout<<abs(a-sisa)<<"\n";
}


Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <unordered_map>
//#include <string>
//typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007

int main() {
    int n;
    vector<int> p;
    int tmp_p;
    int ans=0;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> tmp_p;
        p.push_back(tmp_p);
    }
    sort(p.begin(),p.end());
    p[n-1]/=2;
    for(int i=0; i<n; i++){
        ans+=p[i];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
int main(){
  unsigned long N;
  long double A[5];
  cin >> N >> A[0] >> A[1] >> A[2] >> A[3] >> A[4];
  for(int i=0; i<5; i++){
    for(int j=i+1; j<5; j++){
      if(A[i] > A[j]){
        unsigned long tmp = A[i];
        A[i] = A[j];
        A[j] = tmp;
      }
    }
  }
  unsigned long cnt = (unsigned long)(ceill(N/A[0]));
  cout << cnt+4 << endl;
  return 0;
}

Measured memory_bytes: 1016
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
Scanner s = new Scanner(System.in);
		while (true) {
			
			int n = s.nextInt();
			int p = s.nextInt();
			if (n == 0 && p == 0) {
				break;
			}
			int pos = 0;
			int wan = p;
			int person[] = new int[n];
			for (int i = 0; i < n; i++) {
				person[i] = 0;
			}
			while (true) {
				if (wan != 0) {
					person[pos]++;
					wan--;
					if (person[pos] == p) {
						break;
					} // if2
				} // if2
				else {
					wan = person[pos];
					person[pos] = 0;
				} // else
				pos++;
				if (pos == n) {
					pos = 0;
				} // if3
			} // while2
			System.out.println(pos);
		} // while1
	}// method
}// class

Measured memory_bytes: 27184
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using static System.Console;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        solve();
    }
    static Scanner cin;

    static int H, W;
    static string[] S;
    static void input()
    {
        cin = new Scanner();
        H = cin.nextInt();
        W = cin.nextInt();
        S = new string[H];
        for (int i = 0; i < H; i++)
            S[i] = cin.next();
    }
    static void solve()
    {
        input();
        for(int y = 0; y < H; y++)
            for(int x = 0; x < W; x++)
            {
                if (S[y][x] == '.')
                    continue;
                if (y != 0 && S[y - 1][x] == '#')
                    continue;

                if (x != 0 && S[y][x - 1] == '#')
                    continue;

                if (y != H - 1 && S[y + 1][x] == '#')
                    continue;

                if (x != W - 1 && S[y][x + 1] == '#')
                    continue;

                WriteLine("No");

                return;
            }
        WriteLine("Yes");
    }
    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }
        
        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }

        public double[] ArrayDounble(int N, int add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

Measured memory_bytes: 11092