akhauriyash/Code-Regression huggingface dataset:
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <LL,LL>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL x,y,z,k,a[1010],b[1010],c[1010];
priority_queue <pair <LL,pair <pii,LL> > > q;
map <pair <pii,LL>,bool> mp;

int main()
{
	cin>>x>>y>>z>>k;
	rep(i,x) cin>>a[i];
	rep(i,y) cin>>b[i];
	rep(i,z) cin>>c[i];
	sort(a,a+x);
	sort(b,b+y);
	sort(c,c+z);
	q.push({a[x-1]+b[y-1]+c[z-1],{{x-1,y-1},z-1}});
	mp[mpr(mpr(x-1,y-1),z-1)]=true;
	while(k--)
	{
		pair <LL,pair <pii,LL> > t=q.top();
		q.pop();
		LL ts=t.fi,tx=t.se.fi.fi,ty=t.se.fi.se,tz=t.se.se;
		//cout<<tx<<' '<<ty<<' '<<tz<<' ';
		cout<<ts<<endl;
		if(tx-1>=0&& !mp[mpr(mpr(tx-1,ty),tz)])
		{
			mp[mpr(mpr(tx-1,ty),tz)]=true;
			q.push({a[tx-1]+b[ty]+c[tz],{{tx-1,ty},tz}});
		}
		if(ty-1>=0&& !mp[mpr(mpr(tx,ty-1),tz)])
		{
			mp[mpr(mpr(tx,ty-1),tz)]=true;
			q.push({a[tx]+b[ty-1]+c[tz],{{tx,ty-1},tz}});
		}
		if(tz-1>=0&& !mp[mpr(mpr(tx,ty),tz-1)])
		{
			mp[mpr(mpr(tx,ty),tz-1)]=true;
			q.push({a[tx]+b[ty]+c[tz-1],{{tx,ty},tz-1}});
		}
	}
	rt0;
}

Measured memory_bytes: 1024
#include<cstdio>
#define ll long long
ll arr[55];
ll brr[55];
ll ans=0;
void fun(ll L,ll x)
{
    if(x==arr[L])
    {
        ans+=brr[L];
        return ;
    }
    else
    {
        if(x==1)
        {
            return ;
        }
        else if(x<arr[L-1]+2)
        {
            fun(L-1,x-1);
        }
        else if(x==arr[L]/2+1)
            ans+=brr[L]/2+1;
        else if(x>arr[L-1]+2)
        {
            x=x-arr[L-1]-2;
            ans+=brr[L-1]+1;
            fun(L-1,x);
        }

    }

}
int main()
{
    ll n,x;
    arr[0]=1;
    brr[0]=1;
    for(int i=1;i<=50;i++)
    {
        arr[i]=arr[i-1]*2+3;
        brr[i]=brr[i-1]*2+1;
    }
    ans=0;
    scanf("%lld%lld",&n,&x);
    fun(n,x);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;
using System.Text;
using static System.Math;

class MainClass
{


    public static void Main(string[] args)
    {
        var _ = LnInts();
        print(_[0] * _[1]);
    }


    public static long SumAtoB(long a, long b) { var length = b - a + 1; return (a + b) * (length / 2) + (length % 2 == 1 ? (a + b) / 2 : 0); }
    public static long PowLite(long n, long p, long mod = (long)1e9 + 7) { long ans = 1; long now = n; for (; p > 0; p >>= 1) { if ((p & 1) == 1) { ans *= now; ans %= mod; } now *= now; now %= mod; } return ans; }
    public static void print(object obj) { Console.WriteLine(obj); }
    public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; }
    public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); }
    public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; }
    public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); }
    public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; }
    public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; }
    public static List<T[]> AllPermutation<T>(params T[] array) where T : IComparable { var a = new List<T>(array).ToArray(); var res = new List<T[]>(); res.Add(new List<T>(a).ToArray()); var n = a.Length; var next = true; while (next) { next = false; int i; for (i = n - 2; i >= 0; i--) { if (a[i].CompareTo(a[i + 1]) < 0) break; } if (i < 0) break; var j = n; do { j--; } while (a[i].CompareTo(a[j]) > 0); if (a[i].CompareTo(a[j]) < 0) { var tmp = a[i]; a[i] = a[j]; a[j] = tmp; Array.Reverse(a, i + 1, n - i - 1); res.Add(new List<T>(a).ToArray()); next = true; } } return res; }
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long

int32_t main() {
	IOS;
	int n;
	cin>>n;
	int r=n%10;
	if(r==2 || r==4 || r==5 || r==7 || r==9) cout<<"hon";
	else if(r==3) cout<<"bon";
	else cout<<"pon";
	return 0;
}


Measured memory_bytes: 3628
/**
 *    author:  tourist
 *    created: 11.05.2020 14:08:35       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  set<int> s;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    s.insert(x);
  }
  cout << ((int) s.size() == n ? "YES" : "NO") << '\n';
  return 0;
}


Measured memory_bytes: 9728
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;



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

    for (int i = 0; i < k; i++) {
        if(i%2==0){
            if(a%2==0){
                a/=2;
                b+=a;
            }else{
                a=(a-1)/2;
                b+=a;
            }
        }else{
            if(b%2==0){
                b/=2;
                a+=b;
            }else{
                b=(b-1)/2;
                a+=b;
            }
        }
    }

    cout<<a<<" "<<b<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() 
{
  while (true) {
    string s;
    cin >> s;
    if (s == "-") break;

    int m;
    cin >> m;
    REP(i, m) {
      int h;
      cin >> h;
      string tmp;
      REP(i, h) {
        s.push_back(s[0]);
        s.erase(0, 1);
      }
    }
    cout << s << "\n";
  }
}



Measured memory_bytes: 3088
import Control.Monad

main = do
  n1 <- read <$> getLine
  xs <- forM [1..n1] $ \t ->
    getLine
  n2 <- read <$> getLine
  ys <- forM [1..n2] $ \t ->
    getLine
  putStrLn . show $ solve xs ys

solve :: [String] -> [String] -> Int
solve xs ys =
  let a = rmDup (xs ++ ys)
  in max 0 $ maximum $ map (\x -> length (filter (== x) xs) - length (filter (== x) ys)) a

rmDup :: Eq a => [a] -> [a]
rmDup xs = inRD [] xs
  where
    inRD ys [] = ys
    inRD ys (x:xs) = if x `elem` ys then inRD ys xs else inRD (x:ys) xs


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

int n, m, a[100010], visited[100010], used[100010];
vector<int> g[100010], t[100010];

void dfs(int v, int k)
{
    visited[v]++;
    t[k].push_back(v);
    for(int u: g[v]) if (!visited[u]) dfs(u, k);
}

int main()
{
    cin.sync_with_stdio(0);

    cin>>n>>m;
    for(int i=0; i<n; ++i) cin>>a[i];
    for(int i=0; i<m; ++i) {
        int x, y; cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    int k=0;
    for(int i=0; i<n; ++i) if (!visited[i]) dfs(i, k++);
    if (k==1) return cout<<0<<endl, 0;

    for(int i=0; i<k; ++i)
        sort(begin(t[i]), end(t[i]), [&](auto u, auto v){ return a[u]<a[v]; });

    long res=0;
    for(int i=0; i<k; ++i) {
        res+=a[t[i][0]];
        ++used[t[i][0]];
    }
    vector<int> x;
    for(int i=0; i<n; ++i) if (!used[i]) x.push_back(a[i]);
    if (x.size()<k-2) return cout<<"Impossible"<<endl, 0;

    sort(begin(x), end(x));
    res+=accumulate(begin(x), begin(x)+max(0, k-2), 0L);
    cout<<res<<endl;
}


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

int main() {
int A,B,C,X ;
    cin >> A >> B >> C >> X ;
int count=0;
  
  for (int i=0; i<=A; i++){
   for (int j=0; j<=B; j++){
    for (int k=0; k<=C; k++){
      if(500*i+100*j+50*k==X)
      count ++;
    }
   }
  }
  cout <<  count << endl;  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> h(N);
	for (int i = 0; i < N; ++i) { cin >> h[i]; }

	sort(h.begin(), h.end());
	int ans = 1e9;
	for (int i = 0; i + K - 1 < N; ++i) {
		ans = min(ans, abs(h[i] - h[i + K - 1]));
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
import math
k=int(input())
ans=0

for i in range(1,k+1):
    for j in range(i,k+1):
        for l in range(j,k+1):
            if i==j and j==l:
                ans+=i
#                 print(i,j,l)
                
                
            elif i==j or j==l:
                ans+=3*math.gcd(i,l)
#                 print(i,j,l)
                
                
            else:
                ans+=6*math.gcd(math.gcd(i,j),l)
#                 print(i,j,l)
                
                
            
print(ans)

Measured memory_bytes: 68276
"use strict"

function main(input) {

    input = input.split('\n')
    let n = +input[0];
    let ans = 0;
    let a = input[1].split(" ").map(x => ans += Number(x))
    console.log(ans - n);

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7628
#include<iostream>
#include<string>
using namespace std;
int main() {
	int w, h;
	cin >> h >> w;
	char s[50][50];
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			cin >> s[i][j];
		}
	}
	int dx[4] = { 1, 0, -1, 0 };
	int dy[4] = { 0, 1, 0, -1 };
	string ans = "Yes";
	int flag = 0;
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			if (s[i][j] != '#')continue;
			int num = 0;
			for (int d = 0; d < 4; d++) {
				int ni = i + dy[d];
				int nj = j + dx[d];
				if (ni < 0 or h <= ni) continue;
				if (nj < 0 or w <= nj) continue;
				if (s[ni][nj] == '#')num++;
			}
			if (num == 0) {
				ans = "No";
				flag = 1;
				break;
			}
		}
		if (flag)break;
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 123450
#endif

char c;

void solve() {
    cin>>c;
    if (c >= 'a' && c <= 'z') {
        cout << 'a' << endl;
    } else {
        cout << 'A' << endl;
    }
}



Measured memory_bytes: 3608
<?php

$page = array();
while($line = fgets(STDIN)){
	list($a, $b) = explode(" ", trim($line));
	if(!isset($page[$a])){
		$page[$a] = array();
	}
	$page[$a][] = $b;
}

$word = array_keys($page);
sort($word);

foreach($word as $row){
	$arr = $page[$row];
	sort($arr, SORT_NUMERIC);
	echo $row."\n";
	echo implode($arr, " ")."\n";
}

Measured memory_bytes: 15288
a, b, c, d, e = list(map(int, input().split()))

if a == 0:
    print('1')
    exit()
elif b == 0:
    print('2')
    exit()
elif c == 0:
    print('3')
    exit()
elif d == 0:
    print('4')
    exit()
else:
    print('5')



Measured memory_bytes: 9040
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  string s;
  int n;
  cin>>s;
  n=s.size();
  ll dp[n+1][4];
  for(int i=0;i<=n;i++) for(int j=0;j<=3;j++) dp[i][j]=0;
  dp[0][0]=1;
  for(int i=0;i<n;i++){
    for(int j=0;j<=3;j++){
      dp[i+1][j]+=dp[i][j]*(s[i]=='?'?3ll:1ll);
      dp[i+1][j]%=MOD;
      if((j<3)&&(s[i]=='A'+j||s[i]=='?')){
        dp[i+1][j+1]+=dp[i][j];
        dp[i+1][j+1]%=MOD;
      }
    }
  }
  
  cout<<dp[n][3]<<endl;
  return 0;
}


Measured memory_bytes: 3584
#include<stdio.h>
int main(){
  int k,x,start=-1000000,fin=1000000;
  scanf("%d%d",&k,&x);
  if(x-k+1>start)
    start=x-k+1;
  if(x+k-1<fin)
    fin=x+k-1;
  while(start<=fin){
    printf("%d ",start);
    start++;
  }
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scn = new Scanner(System.in);
		char[] S = scn.nextLine().toCharArray();
		char[] T = scn.nextLine().toCharArray();
		boolean can = false,b = false;
		for(int i = 0;i < S.length;i++) {
			b = false;
			for(int j = 0;j < S.length;j++) {
				if(S[j] != T[j]) {
					b = true;
					break;
				}
			}
			if(!b) {
				can = true;
				break;
			}else{
				char buf = T[0];
				for(int j = 0;j < T.length-1;j++) {
					T[j] = T[j+1];
				}
				T[T.length-1] = buf;
			}
		}
		System.out.println(can?"Yes":"No");
		scn.close();
	}
}


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

typedef long long ll;

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

    if (N % 1000)
    {
        cout << 1000 - (N % 1000) << endl;
    } else {
        cout << N % 1000 << endl;
    }
    

    return 0;
}


Measured memory_bytes: 3636
fun main(args: Array<String>) {
    //素数判定
    fun isPrime(n: Int): Boolean {
        if (n == 2) return true
        if (n < 2 || n % 2 == 0) return false
        val d = Math.sqrt(n.toDouble())
        var i = 3
        while (i <= d) {
            if (n % i == 0) {
                return false
            }
            i += 2
        }
        return true
    }

    val X = readLine()!!.toInt()

    for (i in X..1000000000) {
        if (isPrime(i)) {
            println(i)
            return
        }
    }

}



Measured memory_bytes: 29944
n = int(input())
a = []
b = 0
for i in range(n):
    x = int(input())
    b ^= x
    a += [x^(x-1)]
ans = 0
a.sort()
for x in a[::-1]:
    if b&((x+1)>>1):
        b^=x
        ans += 1

if b == 0:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 7836
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7; 

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF_INT (1<<30)
#define INF_LL (1ll<<62)

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

int a[3];

int main(){
    rep(i,3)cin>>a[i];
    sort(a,a+3);
    if(a[0]==a[1]&&a[1]==a[2])out("No");
    else if(a[0]==a[1]||a[1]==a[2])out("Yes");
    else out("No");
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<int> c(n), s(n), f(n);
    rep(i, n - 1) cin >> c[i] >> s[i] >> f[i];

    vector<int> ans(n, 0);
    rep(i, n - 1){
        ans[i] = s[i] + c[i];
        for(int j = i + 1; j < n - 1; j++){
            if(ans[i] <= s[j]){
                ans[i] = s[j] + c[j];
            }else{
                if(ans[i] % f[j] != 0) ans[i] += f[j] - ans[i] % f[j];
                ans[i] += c[j];
            }
        }
    }
    rep(i, n) cout << ans[i] << endl;
}

Measured memory_bytes: 256
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)



int main() {
	int n;
	cin >> n;
	
	rep(i, 20) {
		rep(j, 15) {
			if (n == (i * 4 + j * 7)) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}




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

int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    REP(i,n)cin>>a[i];
    int q;
    cin>>q;
    REP(i,q)
    {
        int com,b,e;
        cin>>com>>b>>e;
        if(com==0)cout<<*min_element(a.begin()+b,a.begin()+e)<<endl;
        else cout<<*max_element(a.begin()+b,a.begin()+e)<<endl;
    }

}


Measured memory_bytes: 3088
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

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

    let mut ret = 0;
    for i in 0..n {
        let mut acc = 0;
        acc += a[0][0..i+1] .iter().fold(0, |acc, &x| acc + x);
        acc += a[1][i..n] .iter().fold(0, |acc, &x| acc + x);
        ret = std::cmp::max(ret, acc);
    }
    println!("{}", ret);
}

Measured memory_bytes: 4352
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
	int K , S ;
	cin>>K>>S;
	int x , y , z ;
	int count=0;
	for(int x=0 ; x<=K ; x++)
	{
		for(int y=0 ; y<=K ; y++)
		  {
		  	z = S-(x+y);
			if(z<=K &&z>=0)
			   count++;
	      }
	}
	cout<<count;
}

Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())
    students = [input().split() for _ in range(N)]
    checkpoints = [input().split() for _ in range(M) ]
    nearest = [None]*N

    for i, s in enumerate(students) :
        min_d = 10**9

        for j, p in enumerate(checkpoints, 1) :
            a, b = map(int, s)
            c, d = map(int, p)
            d = abs(a - c) + abs(b - d)

            if min_d > d:
                min_d = d
                nearest[i] = j

    for i in range(N):
        print(nearest[i])   
main()

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// #include <cstdio>
// int a;
// scanf("%d", &a);
// printf("%d\n", a);
//
// for (int i=0; i<n; ++i)
// 	scanf("%d", &a[i]);
//
// char c;
// scanf(" %c", &c);
//
// cout << "\n";

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

/*
ll	myPow(ll x, ll n) {
	if (0==n)
		return 1;
	if (0==n%2)
		return myPow(x*x%MOD, n/2);
	else
		return x*myPow(x, n-1)%MOD;
}
*/
ll	myPow(ll x, ll n) {
	ll r=1;
	while(n>0)
		if (0==n%2) {
			x *=x;
			x %=MOD;
			n /=2;
		} else {
			r *=x;
			r %=MOD;
			n--;
		}
	return r;
}

#define	Rep0(i, n)	for (ll i=0; i<n; i++)
#define	Rep1(i, n)	for (ll i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

ll	gcd(ll A, ll B) {
	while (0!=B) {
		A %=B;
		swap(A, B);
	}
	return A;
}

int	main() {
	ll K;
	cin >>K;
	ll S=0;
	Rep1(i, K)
		Rep1(j, K) {
			if (1==gcd(i, j)) {
				S+=K;
				continue;
			}
			ll G=gcd(i, j);
			Rep1(k, K)
				S+=gcd(G, k);
		}
	cout <<S <<endl;
	return 0;
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = (int)1e9 + 7;

const int A = 0, G = 1, C = 2, T = 3;

int N;

//末尾の3文字の中で入れ替えすると条件に反するものを除く
bool isOK3(int x1, int x2, int x3) {
  if ((x1 == A && x2 == G && x3 == C) || (x1 == G && x2 == A && x3 == C) ||
      (x1 == A && x2 == C && x3 == G)) {
    return false;
  } else {
    return true;
  }
}

//末尾の4文字の中で入れ替えすると条件に反するものを除く
bool isOK4(int x1, int x2, int x3, int x4) {
  if ((x1 == G && x2 == A && x3 == C) || (x2 == G && x3 == A && x4 == C) ||
      (x1 == A && x2 == C && x3 == G) || (x2 == A && x3 == C && x4 == G) ||
      (x1 == A && x3 == G && x4 == C) || (x1 == A && x2 == G && x4 == C)) {
    return false;
  } else {
    return true;
  }
}

void abc132d() {
  int dp[102][4][4][4] = {0};

  for (int j = 0; j < 4; j++) {
    for (int k = 0; k < 4; k++) {
      for (int l = 0; l < 4; l++) {
        if (isOK3(j, k, l)) {
          dp[3][j][k][l] = 1;
        }
      }
    }
  }

  for (int i = 3; i < N; i++) {
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 4; k++) {
        for (int l = 0; l < 4; l++) {
          for (int c = 0; c < 4; c++) {
            if (isOK3(k, l, c) && isOK4(j, k, l, c)) {
              dp[i + 1][k][l][c] += dp[i][j][k][l];
              dp[i + 1][k][l][c] %= MOD;
            }
          }
        }
      }
    }
  }

  ll res = 0;

  for (int j = 0; j < 4; j++) {
    for (int k = 0; k < 4; k++) {
      for (int l = 0; l < 4; l++) {
        res += dp[N][j][k][l];
        res %= MOD;
      }
    }
  }
  cout << res << "\n";
}

int main() {
  cin >> N;
  abc132d();
  return 0;
}

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

int semi[2000];
int depth[2000];
int dp[2000];
vector<pair<int,int>> g[2000];
int main(){
  int n;
  cin>>n;
  lp(i,n-1){
    int a;
    cin>>a;
    if(a>0) semi[i+1]=1;
    else semi[i+1]=0;
  }
  lp(i,n-1){
    int a,b,c;
    cin>>a>>b>>c;
    g[a].push_back({b,c});
    g[b].push_back({a,c});
  }
  queue<pair<int,int>> q;
  q.push({0,1});

  
  while(!q.empty()){
    int now=q.front().first;
    int cnt=q.front().second;
    q.pop();
    depth[now]=cnt;
    lp(i,g[now].size()){
      int next=g[now][i].first;
      if(depth[next]!=0) continue;
      q.push({next,cnt+1});
    }
  }
  while(!q.empty()) q.pop();
  q.push({0,0});
  priority_queue<pair<int,int>> pq;
  while(!q.empty()){
    int now=q.front().first;
    q.pop();
    if(semi[now]==1){
      pq.push({depth[now],now});
      dp[now]=INF;
      continue;
    }
    lp(i,g[now].size()){
      int next=g[now][i].first;
      if(depth[next]<depth[now]) continue;
      q.push({next,0});
    }
  }
  while(!pq.empty()){
    int now=pq.top().second;
    int deep=pq.top().first;
    pq.pop();
    lp(i,g[now].size()){
      int next=g[now][i].first;
      if(depth[next]>depth[now]) continue;
      int cost=g[now][i].second;
      if(dp[next]==0) pq.push({depth[next],next});
      dp[next]+=min(dp[now],cost);
    }
  }
  cout<<dp[0]<<endl;
  return 0;
}



Measured memory_bytes: 3260
#include <cstdio>
#include <algorithm>
#include <cmath>

using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using usize = std::size_t;

constexpr double pi = M_PI;

auto main() -> i32 {
	i32 a, b, h, m;
	scanf("%d%d%d%d", &a, &b, &h, &m);
	double acos = std::cos(2. * pi * ((double)h * 60. + (double)m)/ (12. * 60.));
	double asin = std::sin(2. * pi * ((double)h * 60. + (double)m)/ (12. * 60.));
	double bcos = std::cos(2. * pi * (double)m / 60.);
	double bsin = std::sin(2. * pi * (double)m / 60.);
	double xd = (double)a * acos - (double)b * bcos;
	double yd = (double)a * asin - (double)b * bsin;
	printf("%.12lf\n", std::sqrt(xd * xd + yd * yd));
	return 0;
}


Measured memory_bytes: 2564
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pc __builtin_popcount

int d(int x){
	if(x<10){
		return 1;
	}
	return 1+d(x/10);
}

int32_t main(){
	int n;
	cin>>n;
	int mn = 100;
	for(int i=1;i*i<=n;i++){
		if(!(n%i)){
			mn = min(mn,max(d(i),d(n/i)));
		}
	}
	cout<<mn;
}


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

using namespace std;
using ll = long long;

int main() {
	const ll mod = 1000000007;
	ll x, k, ans = 1;
	bool plus = false;
	cin >> x >> k;
	if (x == k) {
		ll a;
		rep(i, x) {
			cin >> a;
			ans = ans * a % mod;
			if (ans < 0) ans += mod;
		}		
		cout << ans << endl;
		return 0;
	}
	if (k % 2 == 0) plus = true;
	vector<ll> p, n;
	rep(i, x) {
		ll a;
		cin >> a;
		if (a >= 0) p.push_back(a);
		else n.push_back(a);
		if (a >= 0 && !plus) plus = true;
	}
	sort(p.rbegin(), p.rend());
	sort(n.begin(), n.end());
	if (plus) {
		int ip = 0, in = 0;
		if (k % 2) {
			ans *= p[0];
			ip++;
			k--;
		}
		while (k) {
			ll pos = 0, neg = 0;
			if (ip + 1 < (int)p.size()) {
				pos = p[ip] * p[ip + 1];
			}
			if (in + 1 < (int)n.size()) {
				neg = n[in] * n[in + 1];
			}
			if (pos >= neg) {
				ans = ans * (pos % mod) % mod;
				ip += 2;
				k -= 2;
			}
			else {
				ans = ans * (neg % mod) % mod;
				in += 2;
				k -= 2;
			}
		}
	}
	else {
		ll i = n.size() - 1;
		while (k) {
			ans = ans * n[i] % mod;
			i--;
			k--;
		}
	}
	if (ans < 0) ans += mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5564
N, M = [int(_) for _ in input().split()]

paths = [[0] * (N + 1) for _ in range(N + 1)]


def has_path(c, t, arrived):
    if c == t: return True
    for i in range(1, N + 1):
        if i in arrived: continue
        if paths[c][i]:
            arrived.append(i)
            if has_path(i, t, arrived):
                return True
            arrived.pop()
    return False


edge = []
for i in range(M):
    a, b = [int(_) for _ in input().split()]
    paths[a][b] = 1
    paths[b][a] = 1
    edge.append((a, b,))

ans = 0
for e in edge:
    paths[e[0]][e[1]] = 0
    paths[e[1]][e[0]] = 0
    if not has_path(e[0], e[1], []):
        ans += 1
    paths[e[0]][e[1]] = 1
    paths[e[1]][e[0]] = 1
print(ans)

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

#ifdef DEBUG
#define NDEBUG
#include "cout11.h"
#endif
#undef NDEBUG
#include <cassert>

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
#define rep(var,n)  for(int var=0;var<(n);++var)
#define ALL(c)  (c).begin(),(c).end()


ll solve(int N, ll H, vi& a, vi& b) {
    int best = 0x7fffffff;

    vector<int> z(ALL(b));
    sort(ALL(z)); reverse(ALL(z));

    vector<ll> ac(N+1, 0);
    rep(i,N) ac[i+1] = ac[i] + z[i]; // どこかでHを超えるかも

    int ai = *max_element(ALL(a));
    rep(i, N+1) {
        ll rem = H - ac[i];
        if (rem > 0) {
            int pls = (rem + ai - 1) / ai;
            best = min(best, i + pls);
        } else {
            best = min(best, i);
        }
    }
    return best;
}

int main() {
    int N, H; cin >> N >> H;
    vector<int> a(N), b(N);
    rep(i, N){
        cin >> a[i] >> b[i];
    }
    cout << solve(N, H, a, b) << endl;
    return 0;
}


Measured memory_bytes: 2176
import java.util.Scanner;

public class Main{

	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		String word = sc.next();
		int count = 0;
		while(sc.hasNext()){
			
			String scanWord = sc.next().toLowerCase();
			
			if("END_OF_TEXT".equals(scanWord)){
				break;
			}
			
			if(scanWord.equals(word)){
				
				count++;
			}
		}
		
		
		System.out.println(count);
		
		
		sc.close();
	}
	
	
}



Measured memory_bytes: 25984
using System;

namespace ABC107_A_Train
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string[] inStr = Console.ReadLine().Split(' ');
			int n = int.Parse(inStr[0]);
			int i = int.Parse(inStr[1]);
			
			Console.WriteLine(n - i + 1);
		}
	}
}

Measured memory_bytes: 13140
import os
import sys
from collections import defaultdict
adj = defaultdict(list)
col = defaultdict(int)
sys.setrecursionlimit(1000000)
mx=0
edges = {}
def find_color(u , p):
	global mx , now
	cnt =0
	for i in adj[u]:
		cnt = cnt+1
		if i==p:
			continue
		find_color(i , u)
	mx = max(mx, cnt)
now =0
def dfs(u , p, prev):
	global mx, now
	for i in adj[u]:
		if i==p:
			continue
		if now == prev:
			now = (now+1)%mx
		col[edges[i,u]]=now
		now =(now+1)%mx
	for i in adj[u]:
		if i==p:
			continue
		dfs(i , u, col[edges[i, u]])

def main():
	n = int(input())
	for i in range(n-1):
		x, y = map(int , input().split())
		adj[x].append((y))
		adj[y].append((x))
		edges[x,y]=i
		edges[y,x]=i
	find_color(1, 0)
	dfs(1, 0,-1)
	print(mx)
	for i in range(n-1):
		print(col[i]+1)


if __name__ == "__main__":
	main()


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

void print(string *A, int N) {
    rep(i, N) {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << "\n";
}

bool isStable(string *A, string *B, int N) {
    rep(i, N) {
        if (A[i] != B[i])
            return false;
    }
    return true;
}

void bubbleSort(string *A, int N) {
    int flag = 1;
    int count = 0;
    int i = 0;
    while (flag) {
        flag = 0;
        for (int j = N-1; j > i; j--) {
            if (A[j][1] < A[j-1][1]) {
                string tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                flag = 1;
                count++;
            }
        }
        i++;
    }
}

void selectionSort(string *A, int N) {
    int count = 0;
    for (int i = 0; i < N; i++) {
        int minj = i;
        for (int j = i; j < N; j++) {
            if (A[j][1] < A[minj][1])
                minj = j;
        }
        if (i != minj) {
            string tmp = A[i];
            A[i] = A[minj];
            A[minj] = tmp;
            count++;
        }
    }
}

int main() {
    int N;
    cin >> N;
    string A[N];
    string B[N];
    rep(i, N) {
        string str;
        cin >> str;
        A[i] = B[i] = str;
    }
    bubbleSort(A, N);
    print(A, N);
    cout << "Stable" << endl;
    selectionSort(B, N);
    print(B, N);
    if (isStable(A, B, N)) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }

    return 0;
}


Measured memory_bytes: 3208
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
  string s; cin>>s;
  vector<char> op(3);
  for(int i=0;i<(1<<4);i++){
    int tmp = s.at(0)-'0';
    for(int j=0;j<3;j++){
      if(i & (1<<j)){
        tmp += s.at(j+1)-'0';
        op.at(j) = '+';
      }else{
        tmp -= s.at(j+1)-'0';
        op.at(j) = '-';
      }
    }

    if(tmp == 7){
      cout<<s.at(0)<<op.at(0)<<s.at(1)<<op.at(1)<<s.at(2)<<op.at(2)<<s.at(3)<<"=7"<<endl;
      break;
    }
  }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	  static int MOD=1000000007;
	  static long p[][]=new long[405][405];
	  static long sum[][]=new long[405][405];
	  static long dp[][]=new long[35][100005];
	  static long a[]=new long[100005];
	  static long b[]=new long[405];
      public static void main(String[] args) {
    	  Scanner in=new Scanner( new BufferedReader(new InputStreamReader(System.in)))	;
          String s=in.next();
          int len=s.length();
          long sum=0;
          for(int i=0;i<(1<<(len-1));i++)
          {
        	  //System.out.println("i:"+i);
        	  int pos=0;
        	  for(int j=0;j<len-1;j++)
        	  {
        		  if((i&(1<<j))!=0)
        		  {
        			  //System.out.println(s.substring(pos,j+1));
        			  sum+=Long.parseLong(s.substring(pos, j+1));
        			  pos=j+1;
        		  }
        	  }
        	 //System.out.println(s.substring(pos,len));
        	  sum+=Long.parseLong(s.substring(pos, len));
          }
         
       System.out.println(sum);
	}
}


Measured memory_bytes: 80336
def factorization(n):
  primen = []
  degree = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      primen.append(i)
      degree.append(cnt)
  if temp!=1:
    primen.append(temp)
    degree.append(1)
  if primen==[]:
    primen.append(n)
    degree.append(1)
  return primen,degree

N = int(input())
ans = factorization(N)
import itertools
T = []
for i in ans[1]:
  T.append(list(range(i+1)))
L = list(itertools.product(*T))
RR = N
for i in L:
  x = 1
  for j in range(len(ans[0])):
    x = x * (ans[0][j]**i[j])
  y = N // x
  R = x - 1 + y - 1
  RR = min(RR,R)
print(RR)

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

int main() {
	long long n, a, b, c, d, e;
	while ( cin >> n >> a >> b >> c >> d >> e ) {
		long long ans = (n-1) / min( min( min( min( a, b ), c ), d ), e ) + 5;
		cout << ans << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(int i=(a);i<(b);++i)

#define huge 1000000007
typedef long long ll;
ll gcd(ll a, ll b);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll X = 0;
	ll M = 0;
	//ll M = 0;
	//ll a[200000] = {};
	//ll b[200000] = {};
	ll v[100] = {};
	ll *a, *b, *x;
	string S,T,U;
	ll count = 0;
	ll sum = 0;
	ll min = 100000;
	ll max = 0;
	int flag = 0;
	char temp,head;
	//int is = 0;
	

	//char p;
	cin >> N ;
	//cin >> S;

	//a = (ll *)malloc(M * sizeof(ll));
	//b = (ll *)malloc(M * sizeof(ll));
	//vector<pair<int,int>> ch(N+1);
	//vector<bool> flag(N);
	
	//count--;
	//	cout << X << endl;
	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(is.begin(), is.end());

	if (N == 1) {
		cout << 1 << endl;
		return 0;
	}

	v[0] = 2;
	v[1] = 1;
	sum = 3;
	rep(i, 2, N) {
		v[i] = sum;
		sum += v[i - 1];
		//cout << sum << endl;
	}

	
	
	//cout << v[0] << v[1] << v[2] << v[3] << endl;

	
		cout << sum << endl;
	

	



	


	return 0;

}

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

	return b;
}

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

using namespace std;

int main(){
	long long n;
	cin >> n;
	vector<long long > a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	vector<long long> v(n);
	long long ans=0;
	while(1){
		long long s=0;
		for(int i=0;i<n;i++){
			v[i]=0;
		}
		for(int i=0;i<n;i++){
			if(a[i]>=n){
				v[i]=(a[i]-n+1)/n;
				a[i]-=n*v[i];
				if(a[i]>=n){
					a[i]-=n;
					v[i]+=1;
				}
				s+=v[i];
			}
		}
		if(s==0)break;
		for(int i=0;i<n;i++){
			a[i]+= s-v[i];
		}
		ans +=s;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
using namespace std;
int a[5]={0,0,0,0,0};
int main()
{
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if(a[1]-a[0]==a[2]-a[1]) cout<<"YES";
	else cout<<"NO";
    return 0; 
} 

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

class Program
{
	static void Main()
	{
		var array1 = new[] { 'A', 'C', 'G', 'T' };
		var array2 = new[] { 'T', 'G', 'C', 'A' };

		var b = Console.ReadLine().First();
		Console.WriteLine(array2[Array.IndexOf(array1, b)]);

		//デバッグ実行での確認用。そのまま提出しても問題なし
		Console.ReadKey();
	}
}


Measured memory_bytes: 18184
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    ll x, y;
    cin >> x >> y;
    x--;  y--;

    vvl G(n);  // 辺の重みがすべて1のグラフ
    rep(i, n-1) {
        G[i].pb(i+1);
        G[i+1].pb(i);
    }
    G[x].pb(y);
    G[y].pb(x);

    vl ans(n);
    rep(sv, n) {
        // BFS。計算量はO(V+E)
        vl dist(n, -1);  // dist[v] : 頂点svから頂点vへの最短距離(-1のとき未訪問)
        queue<ll> Q;
        dist[sv] = 0;
        Q.push(sv);
        while(!Q.empty()) {
            ll v = Q.front();
            Q.pop();
            for(auto u : G[v]) {
                if(dist[u] == -1) {
                    dist[u] = dist[v] + 1;
                    Q.push(u);
                }
            }
        }
        rep(v, n) {
            ans[dist[v]]++;
        }
    }

    exrep(i, 1, n-1) {
        out(ans[i]/2);
    }

    re0;
}

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

int main(){
    int K ,S;
    int flag =0;
    cin >> K >> S;

    //x,yが決まればzは一意に決まるので、S-x-yがK以下かつx+yがS以下のとき、zを使う．
    int cnt = 0;
    for(int x=0;x<=K;x++){
        for(int y=0;y<=K;y++){
            int part = x + y;
            if(S-part <=K && part <= S){
                cnt++;
            }
        }
    }
    cout << cnt;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int R, C, N;
//---------------------------------------------------------------------------------------------------
int parse(int x, int y) {
    if (y == 0) return x;
    else if (x == R) return R + y;
    else if (y == C) return R + C + (R - x);
    return 2 * R + C + (C - y);
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> R >> C >> N;
    vector<pair<int, int>> v;
    rep(i, 0, N) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        if (a != 0 && a != R && b != 0 && b != C) continue;
        if (c != 0 && c != R && d != 0 && d != C) continue;
        v.push_back({ parse(a, b), i });
        v.push_back({ parse(c, d), i });
    }
    sort(v.begin(), v.end());

    stack<int> sta;
    for (auto p : v) {
        if (!sta.empty()) {
            if (sta.top() == p.second) sta.pop();
            else sta.push(p.second);
        }
        else sta.push(p.second);
    }

    if(sta.empty()) printf("YES\n");
    else printf("NO\n");
}

Measured memory_bytes: 2420
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		System.out.println(a%3==0||b%3==0||(a+b)%3==0?"Possible":"Impossible");
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}


Measured memory_bytes: 23764
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = n;
        int sn = 0;
        while (0 < m) {
            sn += m % 10;
            m /= 10;
        }
        if (n % sn == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }    
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define gc getchar
#define re register
#define rep(i,u,z) for(re int i=u;i<=z;++i)
#define reb(i,u,z) for(re int i=u;i>=z;--i)
#define inf 0x7fffffff

using namespace std;
typedef long long ll;

inline int read(){
	int rt=0;
	char ch=gc();
	while(ch<'0'||ch>'9')ch=gc();
	while(ch>='0'&&ch<='9'){
		rt=(rt<<3)+(rt<<1)+(ch&15);
		ch=gc();
	}
	return rt;
}
int main(){
	int x=read(),a=read();
	puts(x<a?"0":"10");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 200005
typedef long long LL;
template<class T>void tomax(T &x,T y){
	if(x<y)x=y;	
}
template<class T>void tomin(T &x,T y){
	if(x>y)x=y;	
}
int A[M];
int main(){
	int mx=0,se=0;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d",&A[i]);
	for(int i=1;i<=n;i++){
		if(A[i]>mx)se=mx,mx=A[i];
		else if(A[i]>se)se=A[i];
	}	
	for(int i=1;i<=n;i++){
		if(A[i]==mx)printf("%d\n",se);
		else printf("%d\n",mx);
	}	
	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
const ll mod = 1e9 + 7;
const int M = 2e6 + 5;
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1LL;
   if(pow < 0) return 0;
   base %= mod;
   while(pow!=0){if(pow&1LL==1LL){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2LL;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;ll c = (a * b)%mod;return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(2e6 + 7)] , inv_fac[(int)(2e6 + 7)];
void precomp_factorial(){fac[0] = 1;for(ll i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(ll i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};

int check(ll mid, vector <ll> vec1, vector <ll> vec2, ll k){
    for(int i = 0; i < vec1.size(); i++){
        if(vec1[i]*vec2[i] <= mid) continue;
        else{
            ll val = mid/vec2[i];
            k -= (vec1[i] - val);
        }
    }
    //cout << k << "||" << mid << endl;
    if(k >= 0) return 1;
    return 0;
}

int main() {
    ll n, k;
    cin >> n >> k;
    vector <ll> vec1(n), vec2(n);
    for(int i = 0; i < n; i++) cin >> vec1[i];
    for(int i = 0; i < n; i++) cin >> vec2[i];
    sort(vec1.begin(), vec1.end());
    sort(vec2.begin(), vec2.end());
    reverse(vec2.begin(), vec2.end());
    ll start = 0LL, end1 = 1e12;
    ll ans = 0;
    while(start <= end1){
        ll mid = (start+end1)/2LL;
          if(check(mid, vec1, vec2, k)){
             ans = mid;
             end1 = mid-1LL;
          } else{
             start = mid+1LL;
          }
    }
    cout << ans;
}


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

int main() {
  ll n;
  cin >> n;
  if(n==0) {
    cout << 0 << endl;
    return 0;
  }
  string ans;
  ll base=1;
  ll temp=2;
  while(n!=0) {
    if(n%temp==0) {
      ans="0"+ans;
    }
    else {
      ans="1"+ans;
      n-=base;
    }
    temp*=2;
    base*=-2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=7005;
int a,b,c,d;
int e,f;
bool water[max_n],sugar[max_n];
int main(){
    scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
    for(int i=0;a*i*100<=f;i++){
        for(int j=0;(a*i+j*b)*100<=f;j++)water[(a*i+j*b)*100]=true;
    }
    for(int i=0;i*c<=f;i++){
        for(int j=0;i*c+j*d<=f;j++)sugar[i*c+j*d]=true;
    }
    int x=0,y=0;
    for(int i=0;i<=f;i++){
        for(int j=0;j+i<=f;j++){
            if(!water[i]||!sugar[j])continue;
            if(100*j>e*i)continue;
            if(j*x>=y*(i+j)){
                x=i+j,y=j;
            }
        }
    }
    printf("%d %d\n",x,y);
    return 0;
}

Measured memory_bytes: 256